2014-01-20 20 views
0

我需要能夠將當前URL列表重寫爲不同域上的新URL。Apache重寫URLS列表

例如

http://oldhost/information/site-map -> http://newhost/regions/ 
http://oldhost/links/ -> http://newhost/links-to-whatever 

但該網址不符合任何在列表中oldhost URL的情況下,重定向到http://newhost

回答

0

將這個代碼在你DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^(www\.)?oldhost\.com$ [NC] 
RewriteRule ^site-map/?$ http://newhost/regions/? [L,NC,R=301] 

RewriteCond %{HTTP_HOST} ^(www\.)?oldhost\.com$ [NC] 
RewriteRule ^links/?$ http://newhost/links-to-whatever? [L,NC,R=301] 

RewriteCond %{HTTP_HOST} ^(www\.)?oldhost\.com$ [NC] 
RewriteRule^http://newhost%{REQUEST_URI} [L,R=301] 
+0

這對我不起作用。雖然我使用它作爲.com.au域名。所以我有:RewriteCond%{HTTP_HOST} ^(www \。)?oldhost \ .com \ .au $ [NC]。 – user1290717

+0

哪個網址沒有爲您重定向? – anubhava