URL新闻ID的RewriteRule

时间:2011-07-09 15:06:22

标签: apache .htaccess url mod-rewrite seo

我有点坚持使用RewriteRule 301,从OLD News id更改为新的新闻ID

这就是我的尝试:

RewriteRule ^/news/0(.*)$ /news/$1 [L,R=301]

假设新闻URL看起来像他的:

http://www.mydomain.com/news/01/title-of-the-new
http://www.mydomain.com/news/09/title-of-the-new
http://www.mydomain.com/news/012/title-of-the-new
http://www.mydomain.com/news/032/title-of-the-new

我想改为:

http://www.mydomain.com/news/1/title-of-the-new
http://www.mydomain.com/news/9/title-of-the-new
http://www.mydomain.com/news/12/title-of-the-new
http://www.mydomain.com/news/32/title-of-the-new

3 个答案:

答案 0 :(得分:1)

我设法修复了替换

RewriteRule ^/news/0(.*)$ /news/$1 [L,R=301] 

RewriteRule ^news/0(.*)$ /news/$1 [L,R=301]

答案 1 :(得分:0)

你为什么需要它?你的规则应该成功,但不是你需要的(我认为)。当您打开http://www.mydomain.com/news/1/title-of-the-new

时,它会以URL http://www.mydomain.com/news/01/title-of-the-new运行您的服务器端srcipts

答案 2 :(得分:0)

我认为删除所有前置零的更强大的规则更好一点:

RewriteRule ^ news / 0 +(。*)$ / news / $ 1 [L,R = 301]