Redirect 使用.htaccess重定向错误

Redirect 使用.htaccess重定向错误,redirect,Redirect,重写url RewriteRule^about//about.php[L,R=301],但该页面也可以通过/about.php直接访问。请帮助了解如何重定向.php文件用以下代码替换代码: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+about\.php\s [NC] Rewrit

重写url RewriteRule^about//about.php[L,R=301],但该页面也可以通过/about.php直接访问。请帮助了解如何重定向.php文件

用以下代码替换代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+about\.php\s [NC]
RewriteRule ^ /about/ [R=302,L]

RewriteRule ^about/?$ /about.php [L,NC]

您可以免费使用此。htaccess重定向生成器


使用此工具,您可以轻松为.htaccess创建重定向代码。

您可以使用规则隐藏重定向:

#use [L] to hidden [R] to shown redirect
RewriteRule ^(about|faq|home)/?$ $1.php [L]

#to prevent access from about.php simply do this:
RewriteRule (.+)\.php$ $1/ [R=301]
#you need to know 301 redirect will be cached with browser for long time
#so if you change rule - will be no effect for some visitors