2014-10-27 144 views
1

我希望將不以尾部斜線結尾的URL重定向到具有相同路徑但位於不同域的URL,但以尾部斜槓結尾的URL。重定向URL,但不將斜槓重定向到具有尾部斜槓的另一個域.htaccess

例如:

origin.example.com\my-awesome-post -> example.com\my-awesome-post\ - redirect 
origin.example.com\my-awesome-post\ - shouldn't be redirected 

我目前的.htaccess配置不起作用:

<IfModule mod_rewrite.c> 
RewriteCond %{REQUEST_URI} /+[^\.]+$ 
RewriteCond %{HTTP_HOST} origin.example.com\.com$ [NC] 
RewriteRule ^(.+[^/])$ http://example.com/%{REQUEST_URI}/ [R=301,L] 
</IfModule> 

任何意見,我怎麼能與htaccess的實現這一目標?

回答

1

RewriteCond有錯誤的正則表達式,使用這樣的規則:

<IfModule mod_rewrite.c> 
    RewriteCond %{REQUEST_URI} ^/[^.]+$ 
    RewriteCond %{HTTP_HOST} =origin.example.com 
    RewriteRule [^/]$ http://example.com%{REQUEST_URI}/ [R=301,L] 
</IfModule> 
+1

感謝@anubhava,它的偉大工程! – 2014-10-28 07:20:57

+0

不客氣,很高興它解決了。 – anubhava 2014-10-28 07:21:37