【发布时间】:2011-08-04 02:33:00
【问题描述】:
我想将我网站的动态网址更改为搜索引擎友好网址
现在像这样的网址 www.website.com/news.php?id=127591 , 我希望它变成这个 www.website.com/news/127591/this-is-article-subject
我添加了这个
RewriteRule ^news/([0-9]+) /news.php?id=$1 [PT]
在我的 .htaccess 文件中。 /news.php?id=123 中的所有内容都更改为 /new/123/this-is-article-subject
问题是,现在我有两个链接指向相同的内容。 /news.php?id=123 和 /new/123/this-is-article-subject 都是完全重复的内容
据说如果搜索引擎发现重复的内容会惩罚这个。
我在网上查了答案,发现了这个,
RewriteCond %{QUERY_STRING} ^id=([0-9]+)
RewriteRule ^news\.php /news/%1? [R=301,L]
HTTP 301 永久重定向从旧 URL 到新 URL。
但这仍然有问题。当我将这三行放在一起时,它不起作用。
RewriteRule ^news/([0-9]+) /news.php?id=$1 [PT]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)
RewriteRule ^news\.php /news/%1? [R=301,L]
我猜原因是递归循环。我该如何解决这种问题?
谢谢!
更新
我改成了这个
RewriteRule ^news/([0-9]+) /news.php?id=$1 [L]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)
RewriteRule ^news\.php /news/%1? [R=301,L]
这两个网址都不起作用。
【问题讨论】:
标签: regex .htaccess mod-rewrite loops recursion