【发布时间】:2012-07-01 13:04:35
【问题描述】:
我遇到的问题是第一个 URL 有效,而第二个无效。
http://www.example.com/podcast/episode1
http://www.example.com/podcast/episode1/
有没有办法将所有尾部斜杠版本重定向到非尾部斜杠版本?
这里的问题更严重,因为这些都不起作用:
example.com/podcast
example.com/podcast/
只有这个有效:
example.com/podcast.html
我不希望 html 扩展可见。
这是我目前在 .htaccess 文件中的代码:
#shtml
AddType text/html .html
AddHandler server-parsed .html
#html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://example.com/ [R=301,L]
#non www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
你能帮帮我吗?
【问题讨论】:
-
还希望将 html 版本重定向到非 html 版本。比如我想让pavlinaplus.com/podcast/reality.html重定向到pavlinaplus.com/podcast/reality
标签: html .htaccess redirect slash trailing