htaccess的重定向规则去除文章编号 [英] .htaccess redirect rule for for removing article id
本文介绍了htaccess的重定向规则去除文章编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想重定向以下网址:
发件人: http://www.example.com/13-articlename
TO: http://www.example.com/articlename
和我有以下code:
的RewriteCond%{QUERY_STRING} ID = 13
重写规则(。*)$ http://www.example.com/articlename [R = 301,L]
解决方案
在你重写你期待 ID的查询参数
然而,在你的榜样,它实际上是部分该网址。
RewriteEngine叙述上
的RewriteBase /
重写规则(\ d +) - ([^ /] *)$ 2 [R = 301,L]
-
(\ d +)
=匹配任何数字 -
-
=一个连字符 -
([^ /] *)
=,除了正斜杠的任何字符 -
$ 2
=重定向到第二个匹配组 -([^ /] *)
-
[R = 301]
=使用HTTP 301重定向(忽略,如果你想拥有它改写,而不是重定向) -
[L]
=最后一个规则(不处理下列规则)
您可以在 http://htaccess.madewithlove.be/
测试 输入网址
http://www.example.com/13-articlename
输出网址
http://www.example.com/articlename
调试信息
1 RewriteEngine叙述上
2的RewriteBase /
3重写规则(\ d +) - ([^ /] *)$ 2 [R = 301,L]
这条规则是满足,新的URL http://www.example.com/articlename
测试被停止,因为在你的重写规则选项R的。
一个重定向将与状态code 301进行
I want to redirect the following URLs:
From: http://www.example.com/13-articlename
TO: http://www.example.com/articlename
And I have following code:
RewriteCond %{QUERY_STRING} id=13
RewriteRule (.*)$ http://www.example.com/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 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
这篇关于htaccess的重定向规则去除文章编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文