mod-rewrite递归循环 [英] mod-rewrite recursive loop

查看:206
本文介绍了mod-rewrite递归循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的网站的动态网址搜索引擎友好的URL

I want to change my website's dynamic urls to Search Engine Friendly URL's

现在这样www.website.com/news.php?id=127591的URL, 我希望它成为本www.website.com/news/127591/this-is-article-subject

Now the urls like this www.website.com/news.php?id=127591 , I want it became this www.website.com/news/127591/this-is-article-subject

我说这

RewriteRule ^news/([0-9]+) /news.php?id=$1 [PT]

在我的.htaccess文件。一切从/news.php?id=123变化/新/ 123 /本,是-文章,题目

in my .htaccess file. Everything from /news.php?id=123 change to /new/123/this-is-article-subject

的问题是,现在我有两个链接指向了相同的内容。无论/news.php?id=123和/新/ 123 /本,是-文章,题目是完全重复的内容

有人说,搜索引擎将惩罚这一点,如果他们发现重复的内容。

It is said that search engine will punish this if they found duplicated contents.

我核对答案,并在网上发现了这一点,

I check the answers online and found this,

RewriteCond %{QUERY_STRING} ^id=([0-9]+) 
RewriteRule ^news\.php /news/%1? [R=301,L]

HTTP 301从旧的URL永久重定向到新的URL。

HTTP 301 permanent redirect from the old URL to the new URL.

但是,这仍然有问题。当我把这些三线在一起,岂不作品。

But this still have problem. When I put those three lines together, it not works.

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]

无两URL的工作。

None of the two url work.

推荐答案

请尝试这条规则在您的.htaccess文件:

Please try this rule in your .htaccess file:

RewriteEngine on
Options +FollowSymlinks -MultiViews

RewriteCond %{THE_REQUEST} \?id=([0-9]+)\s [NC]
RewriteRule ^news\.php /news/%1? [R=301,L]

RewriteRule ^news/([0-9]+) /news.php?id=$1 [L,NS,NE,QSA,NC]

更新::根据您的意见:

news.php 当URL没有 /一些标题然后再输出这个元标记阻止索引 /新闻/ 987 键入的URI:

UPDATE:: Based on your comments:

Inside news.php when URL doesn't have /some-title then output this META tag to stop indexing /news/987 type URIs:

<meta name="robots" content="NOINDEX, NOFOLLOW">

一旦你发现的URI /新闻/ 987 /一些标题 news.php 只是掩盖上面META标签。 我已经测试它,似乎是美好的工作,所以让我知道,如果不为你工作。

Once you notice URI of /news/987/some-title inside news.php simply mask above META tag. I have tested it and seems to be working fine so let me know if doesn't work for you.

这篇关于mod-rewrite递归循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆