0

我正在使用下面的代碼將index.html和非www版本的URL重定向到www。它還從文件中刪除* .html擴展名。現在,我想在所有目錄中的文件末尾添加尾部斜槓。以下是我想要得到的例子:刪除html擴展並在所有目錄中添加尾部斜槓而不影響內部URL地址

  • www.mydomain.com.au/contact.html去www.mydomain.com.au/contact/
  • www.mydomain.com.au /接觸進入www.mydomain.com.au/contact/
  • www.mydomain.com.au/glass-replacement/Brisbane.html進入 /玻璃 - 替換/布里斯班/

等...

RewriteEngine On 
RewriteBase/

RewriteCond %{THE_REQUEST} ^.*\/index\.html\ HTTP/ 
RewriteRule ^(.*)index\.html$ /$1 [R=301,L] 
RewriteCond %{http_host} ^mydomain.com.au$ [nc] 
RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [r=301,nc,L] 

RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\ [NC] 
RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L] 
RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteRule ^(.+)\.html$ /$1 [R=301,L] 
RewriteCond %{SCRIPT_FILENAME}.html -f 
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L] 

感謝您的幫助提前

+0

所以你要重定向到'/富/'如果用戶只要求'/ foo'? – CBroe 2013-03-18 16:39:54

+0

@CBroe是的。那就對了。 – Webnerdoz 2013-03-18 16:40:57

回答

0

試試這個:

RewriteEngine On 
RewriteBase/

RewriteCond %{THE_REQUEST} ^.*\/index\.html\ HTTP/ 
RewriteRule ^(.*)index\.html$ /$1 [R=301,L] 
RewriteCond %{http_host} ^glassnow.com.au$ [nc] 
RewriteRule ^(.*)$ http://www.glassnow.com.au/$1 [r=301,nc,L] 

RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\ [NC] 
RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L] 
RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteRule ^(.+)\.html$ /$1 [R=301,L] 
RewriteCond %{SCRIPT_FILENAME}.html -f 
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ^(.*)$ http://www.glassnow.com.au/$1/ [R=301,L] 
相關問題