我一堆旧网址的,像这样的:重定向的所有文件中的子文件夹与htaccess的301
www.example.it/modules/prestapress/content.php?id=48
www.example.it/modules/prestapress/content.php?id=47
www.example.it/modules/prestapress/content.php?id=46
我想改写这个网址,以获取ID和重定向到这些网址:
www.example.com/it/blog/48
www.example.com/it/blog/47
www.example.com/it/blog/46
因此,网站将从.it更改为.com,我需要一条规则将所有旧文章博客重定向到新文章网址(通过ID)。
这里的.htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} \bid=(\d+) [NC]
RewriteCond %{HTTP_HOST} ^example\.it [NC]
RewriteRule ^modules/prestapress/content.php$ http://example.com/it/blog/%1? [R=301,L]
,但以这种方式,如果我尝试访问:
example.it/modules/prestapress/content.php?id=48
它重定向到
example.com/it/blog/
没有mantaining的ID。
正确的问题! @ hjpotter92的建议是正确的,但打斗VS这个其他规则,我有,这里总结:
RewriteEngine On
#For redirecting urls blog
RewriteCond %{QUERY_STRING} \bid=(\d+) [NC]
RewriteCond %{HTTP_HOST} ^example\.it [NC]
RewriteRule ^modules/prestapress/content.php$ http://example.com/it/blog/%1-? [R=301,L]
#FOR REDIRECT .IT to .COM for all others urls
RewriteCond %{HTTP_HOST} ^(www\.)?example\.it$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
所以问题是2点,我必须重定向到。它.COM,因为.COM有相同的结构。它的,所以这个规则我解决了:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.it$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
变化是文章的博客结构,并为我们有这样做的唯一的事情:
RewriteCond %{QUERY_STRING} \bid=(\d+) [NC]
RewriteCond %{HTTP_HOST} ^example\.it [NC]
RewriteRule ^modules/prestapress/content.php$ http://example.com/it/blog/%1-? [R=301,L]
,但以这种方式网址重定向博客不起作用!
终于解开了,原来的规则是不正确的,TO完美的作品这里的解决方案:
RewriteEngine On
#For redirecting urls blog
RewriteCond %{QUERY_STRING} \bid=(\d+) [NC]
##WRONG RULE## RewriteCond %{HTTP_HOST} ^example\.it [NC]
RewriteRule ^modules/prestapress/content.php$ http://example.com/it/blog/%1-? [R=301,L]
#FOR REDIRECT .IT to .COM for all others urls
RewriteCond %{HTTP_HOST} ^(www\.)?example\.it$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
你不想从'.it'移动到'.com'吗? – hjpotter92
是啊!对不起,我只是再次编辑,是一个错误。 –
'blog'里面没有其他重写规则吗?它是否将您重定向到'example.com/blog /'或'example.com/it/blog/'? – hjpotter92