我一堆舊網址的,像這樣的:重定向的所有文件中的子文件夾與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