2013-01-08 114 views
0

我試圖用htaccess來做到這一點,但它無法正常工作。將子域中的多個目錄重定向到正常域

例如,我需要重定向:

http://sub.domain.com/category/http://www.domain.com/sub/category/ http://sub.domain.com/category/movies/到http://www.domain.com/sub/listings/movies/ http://sub.domain.com/category/movies /恐怖/到http://www.domain.com/sub/listings/movies/horror/ http://sub.domain.com/events/到http://www.domain.com/sub/local/events/

這是我試圖做的,但其中一些像/ category /正在捕獲所有這些。我想用一個斜線和斜線進行精確匹配,就是這樣。不是子文件夾或文件。我將htaccess文件放在sub.domain.com根目錄下。

Redirect 301 /category/ http://www.domain.com/sub/category/ 
Redirect 301 /category/movies/ http://www.domain.com/sub/listings/movies/ 
Redirect 301 /category/movies/horror/ http://www.domain.com/sub/listings/movies/horror/ 
Redirect 301 /events/ http://www.domain.com/sub/local/events/ 

回答

2

我發現很容易與mod_rewrite的指令,例如:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ 
RewriteCond %{REQUEST_URI} ^/category/?$ [NC] 
RewriteRule .* http://www.domain.com/sub/category/ [R=301,L] 

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ 
RewriteCond %{REQUEST_URI} ^/category/movies/?$ [NC] 
RewriteRule .* http://www.domain.com/sub/listings/movies/ [R=301,L] 

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ 
RewriteCond %{REQUEST_URI} ^/category/movies/horror/?$ [NC] 
RewriteRule .* http://www.domain.com/sub/listings/movies/horror/ [R=301,L] 

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ 
RewriteCond %{REQUEST_URI} ^/events/?$ [NC] 
RewriteRule .* http://www.domain.com/sub/local/events/ [R=301,L] 

據:

I want to do exact match with just a trailing slash and no slash and that's it. Not sub folders or files.

它將永久重定向的URL在你的問題中描述

+0

太棒了!這是完美的。謝謝! – zen