我有一个旧域(old.com),它有大量的动态urls和静态urls,它们在google中都有很好的位置。我有一个新的域名(new.cat),其中相同的内容有新的urls,更环保友好。
old.com站点位于IIS主机中,因此我已经将其转移到带有apache的服务器上,在那里我可以使用htaccess将旧的urls重定向到新的urls。我从数据库中用php完成了它,这样就不用手工编写每一条指令了。
示例动态旧urls ==>新urls:
==> /mots.asp?nm=1 ==> new.cat/moix old.com/mots.asp?nm=2 ==> new.cat/miol
示例静态旧urls ==>新urls:
.frases=‘frases 2’> old.com/mot_cerca_tema.asp?tipus=frases%20fetes ==>新.
嗯,我的.htaccess文件有两种规则:
将301个->重定向到静态旧urls (不含参数),ReweriteRule ->用于动态旧urls (带参数)
这是一种规则(我有更多的规则,但我只是为了弄清楚而设置的。)"new.cat“实际上充满了httpp://协议)
Redirect 301 /mesos.asp new.cat/mots/arxiu-cronologic/
Redirect 301 /inici.asp new.cat/
Redirect 301 /mot_cerca.asp new.cat/mots/arxiu-cronologic/
RewriteEngine on
RewriteCond %{QUERY_STRING} ^nm=1$
RewriteRule ^mot.asp$ new.cat/moix/ [R=301,L]
RewriteCond %{QUERY_STRING} ^nm=2$
RewriteRule ^mot.asp$ new.cat/miol/ [R=301,L]
RewriteRule ^mot_cerca_resultat.asp$ new.cat/miol/ [R=301,L]
RewriteCond %{QUERY_STRING} ^nm=3$
RewriteRule ^mot.asp$ new.cat/gat-vell/ [R=301,L]
RewriteRule ^mot_cerca_resultat.asp$ new.cat/gat-vell/ [R=301,L]
#last rule for all the other dynamic urls
RewriteRule ^(.*)$ new.cat/$1 [R=301,L]问题是“重定向301”规则没有执行,导致404错误,因为最后执行的是de规则。
例如:
old.com/mesos.asp results in new.cat/mesos.asp (that not exists in new.cat)有什么线索能帮我解决这个问题吗?我想有某种偏好问题,但我不明白为什么。我认为问题可能是因为urls的.asp扩展,但是如果规则很好地独立工作,或者与重写器一起工作,那就没有问题了。
新的网站有wordpress作为后端,从那里我可以处理来自old.com的404个错误,并将它们重定向到一个特殊的页面。
多亏了所有人。
发布于 2015-05-26 19:39:02
您正在混合来自两个不同模块的指令,mod_rewrite和mod_alias。由于两个模块都被应用于相同的请求,而且两个模块都不关心另一个模块在做什么,所以您可以让两个模块重定向相同的请求。为了防止这种情况,只需使用mod_rewrite:
RewriteEngine on
RewriteRule ^mesos.asp new.cat/mots/arxiu-cronologic/ [L,R=301]
RewriteRule ^inici.asp new.cat/ [L,R=301]
RewriteRule ^mot_cerca.asp new.cat/mots/arxiu-cronologic/ [L,R=301]
RewriteCond %{QUERY_STRING} ^nm=1$
RewriteRule ^mot.asp$ new.cat/moix/ [R=301,L]
RewriteCond %{QUERY_STRING} ^nm=2$
RewriteRule ^mot.asp$ new.cat/miol/ [R=301,L]
RewriteRule ^mot_cerca_resultat.asp$ new.cat/miol/ [R=301,L]
RewriteCond %{QUERY_STRING} ^nm=3$
RewriteRule ^mot.asp$ new.cat/gat-vell/ [R=301,L]
RewriteRule ^mot_cerca_resultat.asp$ new.cat/gat-vell/ [R=301,L]
#last rule for all the other dynamic urls
RewriteRule ^(.*)$ new.cat/$1 [R=301,L]在这里,L阻止重写引擎执行以下任何规则,以便当您请求/mesos.asp时,它立即重定向,重写引擎停止,这样它就不会执行动态url规则。
https://stackoverflow.com/questions/30466187
复制相似问题