本文介绍了htaccess的重定向规则去除文章编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想重定向以下网址:
发件人: www.example/13-articlename TO: www.example/articlename
和我有以下code:
的RewriteCond%{QUERY_STRING} ID = 13 重写规则(。*)$ www.example/articlename [R = 301,L]解决方案
在你重写你期待 ID的查询参数然而,在你的榜样,它实际上是部分该网址。
RewriteEngine叙述上 的RewriteBase / 重写规则(\ d +) - ([^ /] *)$ 2 [R = 301,L]
- (\ d +) =匹配任何数字
- - =一个连字符
- ([^ /] *) =,除了正斜杠的任何字符
- $ 2 =重定向到第二个匹配组 - ([^ /] *)
- [R = 301] =使用HTTP 301重定向(忽略,如果你想拥有它改写,而不是重定向)
- [L] =最后一个规则(不处理下列规则)
您可以在 htaccess.madewithlove.be/
测试 输入网址 www.example/13-articlename 输出网址 www.example/articlename 调试信息 1 RewriteEngine叙述上 2的RewriteBase / 3重写规则(\ d +) - ([^ /] *)$ 2 [R = 301,L] 这条规则是满足,新的URL www.example/articlename 测试被停止,因为在你的重写规则选项R的。 一个重定向将与状态code 301进行I want to redirect the following URLs:
From: www.example/13-articlename TO: www.example/articlename
And I have following code:
RewriteCond %{QUERY_STRING} id=13 RewriteRule (.*)$ www.example/articlename [R=301,L]解决方案
In your rewrite you are expecting a querystring parameter of id however in your example it is actually part of the URL.
RewriteEngine on RewriteBase / RewriteRule (\d+)-([^/]*) $2 [R=301,L]
- (\d+) = match any digits
- - = a hyphen
- ([^/]*) = any characters except a forward slash
- $2 = redirect to the second matching group - ([^/]*)
- [R=301] = use a HTTP 301 redirect (omit if you want to have it rewrite instead of redirect)
- [L] = Last rule (don't process following rules)
You can test at htaccess.madewithlove.be/
input url www.example/13-articlename output url www.example/articlename debugging info 1 RewriteEngine on 2 RewriteBase / 3 RewriteRule (\d+)-([^/]*) $2 [R=301,L] This rule was met, the new url is www.example/articlename Test are stopped, because of the R in your RewriteRule options. A redirect will be made with status code 301
更多推荐
htaccess的重定向规则去除文章编号
发布评论