Regex .htacces不带尾随斜杠重定向到带尾随斜杠的
我正在使用这个.htaccess,里面有:Regex .htacces不带尾随斜杠重定向到带尾随斜杠的,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我正在使用这个.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
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]
但我没有重定向到->(以及其他第2页和第3页)。由于我在本地进行了测试,我的url将
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]
仍然无法工作,我是否必须在RewriteCond%{HTTP_HOST}^www\.(.+)$[NC]中的第一个点后替换?NE和NC代表什么?还有-d是所有递归目录吗?仅供参考,我正在本地主机中测试我正在输入(和另一个)并给我错误301-永久移动为什么
/example/
在这两者之间,你没有在任何地方提到它?其中,.htaccess位于根文件夹中的/example/
。在远程“”和本地:“”中,这两种情况下都应该是HTTP_主机等效的,不是吗?没有HTTP_主机只包含localhost
。如果将.htaccess放在/example/
文件夹中,则它会有所不同。