使用.htaccess进行多次重定向

时间:2010-07-30 13:17:54

标签: .htaccess redirect

我的网站的文件扩展名为.php。截至目前我已经设置了使用.htaccess重写服务器端以从文件名中删除.php使其成为example.com/filename,我还将其设置为重定向/文件名为/ filename /。我现在想让它将/filename.php重定向到/ filename /。我怎么能这样做?

我现在拥有的是:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([^/]+/)*[^./]+)/$ /$1.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
</IfModule>

1 个答案:

答案 0 :(得分:1)

这将进行重定向并发送301状态代码,告诉浏览器和搜索引擎它是永久重定向。

RewriteRule ^(.*)\.php$ $1/ [R=301,NC]
相关问题