我想重定向以下 URL:
从: http ://www.example.com/13-articlename
到: http ://www.example.com/articlename
我有以下代码:
RewriteCond %{QUERY_STRING} id=13
RewriteRule (.*)$ http://www.example.com/articlename [R=301,L]
我想重定向以下 URL:
从: http ://www.example.com/13-articlename
到: http ://www.example.com/articlename
我有以下代码:
RewriteCond %{QUERY_STRING} id=13
RewriteRule (.*)$ http://www.example.com/articlename [R=301,L]
在您的重写中,您期望一个查询字符串参数,id
但在您的示例中它实际上是 URL 的一部分。
RewriteEngine on
RewriteBase /
RewriteRule (\d+)-([^/]*) $2 [R=301,L]
(\d+)
= 匹配任何数字-
= 连字符([^/]*)
= 除正斜杠外的任何字符$2
= 重定向到第二个匹配组 -([^/]*)
[R=301]
= 使用 HTTP 301 重定向(如果你想让它重写而不是重定向,请省略)[L]
= 最后一条规则(不处理以下规则)您可以在http://htaccess.madewithlove.be/进行测试
input url
http://www.example.com/13-articlename
output url
http://www.example.com/articlename
debugging info
1 RewriteEngine on
2 RewriteBase /
3 RewriteRule (\d+)-([^/]*) $2 [R=301,L]
This rule was met, the new url is http://www.example.com/articlename
Test are stopped, because of the R in your RewriteRule options.
A redirect will be made with status code 301