[英]Apache htaccess 301 redirect
I want to rewrite url from article.php?id=123 to article/123 我想将URL从article.php?id = 123重写为article / 123
I added the following rule, it works fine 我添加了以下规则,效果很好
RewriteRule ^article/(.*) /article.php?id=$1 [PT]
I also want to add a 301 redirect rule to let search engine know article.php?id=123 should move to article/123. 我还想添加301重定向规则,以使搜索引擎知道article.php?id = 123应该移至article / 123。 I added the following rule but seems not working.
我添加了以下规则,但似乎不起作用。
RewriteRule ^article.php?id=(.*)$ /article/$1 [R=301,L]
尝试这样:
RewriteRule ^article.php?id=(.*)$ /article/$1 [L,R=301]
You need to match against the actual request and not the URI because the URI gets rewritten by other rules: 您需要与实际请求而不是URI进行匹配,因为URI被其他规则重写:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /article\.php\?id=([^\ ]+)
RewriteRule ^article\.php$ /article/%1? [R=301,L]
If you don't match against the actual request, a redirect loop will occur: 如果您与实际请求不匹配,则会发生重定向循环:
/article.php?id=123
/article.php?id=123
/article/123
/article/123
/article/123
/article/123
/article.php?id=123
/article.php?id=123
重写为/article.php?id=123
/article/123
/article/123
/article/123
/article/123
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.