htaccess rewriteRule广泛的网址

时间:2014-02-26 12:57:17

标签: .htaccess magento mod-rewrite redirect

我将多商店Magento网站移到了其他域名。 为了重定向所有页面,我使用了一个htaccess文件。

旧域名是:

www.olddomain.nl -> www.newdomain.nl
www.olddomain.nl/categoryone -> www.newdomaincategoryone.nl
www.olddomain.nl/categorytwo -> www.newdomaincategorytwo.nl
www.olddomain.nl/categorythree -> www.newdomaincategorythree.nl

这是有效的,但是当路径更广泛时,它就不再起作用了。

例如:

 http://www.oldomain.nl/categoryone/subcategory/product to
 http://www.newdomaincategoryone.nl/subcategory/product

htaccess代码是:

 <IfModule mod_rewrite.c>
     Options +FollowSymlinks -MultiViews
     RewriteEngine On
     RewriteBase /

         RewriteCond %{HTTP_HOST} ^.*olddomain\.nl [OR]
     RewriteCond %{HTTP_HOST} ^www\.olddomain\.nl  [NC]

     RewriteRule ^categoryone/?$(.*)  http://www.newdomaincategoryone.nl/$1 [R=301,NC]
     RewriteRule ^categorytwo/?$(.*)  http://www.newdomaincategorytwo.nl/$1 [R=301,NC]
     RewriteRule ^/?$(.*) http://www.newdomain.nl [R=301,NC]
 </IfModule>

1 个答案:

答案 0 :(得分:0)

您的规则和正则表达式不正确。

您可以使用此代码:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.nl$  [NC]
RewriteRule ^categoryone(/.*)?$ http://www.newdomaincategoryone.nl$1 [R=301,NC,L]

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.nl$  [NC]
RewriteRule ^categorytwo(/.*)?$ http://www.newdomaincategorytwo.nl$1 [R=301,NC,L]

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.nl$  [NC]
RewriteRule ^/?$ http://www.newdomain.nl [R=301,NC,L]