删除html扩展并在所有目录中添加尾部斜杠而不影响内部URL地址
问题描述:
我正在使用下面的代码将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]
感谢您的帮助提前
答
试试这个:
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]
所以你要重定向到'/富/'如果用户只要求'/ foo'? – CBroe 2013-03-18 16:39:54
@CBroe是的。那就对了。 – Webnerdoz 2013-03-18 16:40:57