Apache 正在将子域中的多个目录重定向到普通域

Apache 正在将子域中的多个目录重定向到普通域,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我正试图用htaccess实现这一点,但它不能正常工作 例如,我需要重定向: 到 http://sub.domain.com/category/movies/ 到 http://sub.domain.com/category/movies/horror/ 到 http://sub.domain.com/events/ 到 下面是我试图做的,但其中一些人喜欢/category/正在捕获所有这些内容。我想用一个尾随斜杠和一个不斜杠来做精确匹配,就这样。不是子文件夹或文件。我将htaccess文件放在

我正试图用htaccess实现这一点,但它不能正常工作

例如,我需要重定向:

到 http://sub.domain.com/category/movies/ 到 http://sub.domain.com/category/movies/horror/ 到 http://sub.domain.com/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/

我发现使用mod_重写指令更容易,如下所示:

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]
根据:

我想用一个尾随斜杠和一个不斜杠来进行精确匹配,就这样。不是子文件夹或文件。

它将永久重定向URL,如问题中所述