2017-09-16 175 views
2

對我的問題可能有一個非常簡單的答案,但經過幾個小時的瀏覽,我仍然沒有找到解決方案,所以非常感謝您的幫助。也許我應該提到,我在Bluehost中使用了一個子域(同一個帳戶上有多個域)。Htaccess Rewrite漂亮URL

我想改寫:www.example.com/myfolderwww.example.com/index.php?s=myfolder

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/?$ /index.php?s=$1 [L] 
  • example.com/abcd - >工作
  • example.com/abcd/ - >的作品,但破壞了我的圖片的URL
  • example.com/abcd/index.php - >不起作用(重定向我 主頁)

非常感謝您的幫助。 羅蘭

回答

0

要重寫索引,使用:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)/?$ /index.php?s=$1 [L] 

而且對CSS,腳本或圖片,使用絕對s鏈接(以/http://...開頭)或在html頭文件中添加<base href="/">

+1

非常感謝!有用! –