0

我正在使用下面的代码将 index.html 和非 www 版本的 URL 重定向到 www。它还从文件中删除 *.html 扩展名。现在,我想在所有目录的文件末尾添加一个斜杠。以下是我想要获得的示例:

  • www.mydomain.com.au/contact.html 转到 www.mydomain.com.au/contact/
  • www.mydomain.com.au/contact 转到 www.mydomain.com.au/contact/
  • www.mydomain.com.au/glass-replacement/Brisbane.html 转到 /glass-replacement/Brisbane/

等等……

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]

提前感谢您的帮助

4

1 回答 1

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]
于 2013-04-02T09:55:29.470 回答