2015-04-07 84 views
0

我一堆旧网址的,像这样的:重定向的所有文件中的子文件夹与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] 
+0

你不想从'.it'移动到'.com'吗? – hjpotter92

+0

是啊!对不起,我只是再次编辑,是一个错误。 –

+0

'blog'里面没有其他重写规则吗?它是否将您重定向到'example.com/blog /'或'example.com/it/blog/'? – hjpotter92

回答

-1

尝试以下操作:

RewriteEngine On 
RewriteCond %{QUERY_STRING} \bid=(\d+) [NC] 
RewriteCond %{HTTP_HOST} ^www\.site\.it [NC] 
RewriteRule ^modules/prestapress/content.php$ http://www.new-site.com/blog/%1? [R=301,L] 

不要使用%1?从重定向的URL中移除的查询字符串。

+0

不起作用!我也无法理解此RewriteCond%{QUERY_STRING} \ bid =(\ d +)[NC] –

+0

@ Wrs-evotechRacingParts'%{QUERY_STRING}'是匹配'?id ='部分网址。 – hjpotter92

+0

感谢%{QUERY_STRING} :)的解释。是的mod_rewrite已启用!.htaccess中没有其他规则。重定向工作如果我的数字是:www.site.it/modules/prestapress但 –

相关问题