[英]Using .htaccess to redirect a directory with or without a trailing slash
[英].htacces without trailing slash redirect to with trailing slash
我在里面使用这个.htaccess:
DirectoryIndex index.php index.html
DirectorySlash On
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/(page1|page2|page3)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
#Show every html,htm and xml as php
RewriteRule ^(.*)\.html$ $1.php [nc]
RewriteRule ^(.*)\.htm$ $1.php [nc]
RewriteRule ^(.*)\.xml$ $1.php [nc]
但我没有将http://example.com/page1重定向到-> http://example.com/page1/ (以及其他page2和page3)。 由于我在本地进行了测试,因此我的网址将是localhost / example / page1,并且应该重定向到localhost / example / page1 /,是否有人看到任何问题?
要添加尾部斜杠,您可以使用如下规则:
DirectoryIndex index.php index.html
DirectorySlash On
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1/ [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(page1|page2|page3)$ /$1/ [R=301,L,NC]
#Show every html,htm and xml as php
RewriteRule ^(.+?)\.(?:xml|html?)$ $1.php [NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.