我从某个地方得到这个密码..。它所做的基本上是删除.php扩展
RewriteEngine On
RewriteRule ^Start/?$ index.php [NC,L]
RewriteRule ^Info/?$ info.php [NC,L]
RewriteRule ^Gallery/?$ gallery.php [NC,L]它做的很好,但由于一些SEO的东西,我需要添加自动跟踪斜杠在最后。
现在它是sitename.com/Start,但它必须重写为sitename.com/start/
有什么解决办法吗?
发布于 2013-07-29 10:32:48
您应该使用301重定向来处理此问题,将其置于您已经定义的规则之上:
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 还值得删除您已经定义的规则中的可选尾斜杠标志,因此您生成的.htaccess文件如下所示:
RewriteEngine On
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^Start/$ index.php [NC,L]
RewriteRule ^Info/$ info.php [NC,L]
RewriteRule ^Gallery/$ gallery.php [NC,L]为了避免第一个条件重写有效文件,您应该添加另一个条件:
RewriteCond %{REQUEST_FILENAME} !-f最后,您的.htaccess应该如下所示:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^Start/$ index.php [NC,L]
RewriteRule ^Info/$ info.php [NC,L]
RewriteRule ^Gallery/$ gallery.php [NC,L]https://stackoverflow.com/questions/17921671
复制相似问题