简体   繁体   中英

Using RewriteCond and RewriteRule to redirect one page

When a user navigates to http://mydomain.nl/nl/my-page/

I need the user to be redirected to http://mydomain.nl/fnl/my-page/

This is because the website I'm working on is a multi-store multi-language Magento webshop which was wrongly configured by someone before me, so that each language has its own store scopes rather than each store having its on language scopes.

I have the following code in my .htaccess :

RewriteCond %{HTTP_HOST} ^mydomain\.nl$ [NC]
RewriteRule ^/nl/terms-and-conditions-of-use/ http://mydomain.nl/fnl/terms-and-conditions-of-use/ [NC,QSA,R]

Basically, what I assume this does is check that it's on the proper domain (that being mydomain.nl) then redirecting the URL so that the user see's the proper page.

The redirect isn't working. If I click on it - it takes me back to the home page of the main domain (that then being anotherdomain.nl)

Could someone take a look at it and see what I'm doing wrong?

-EDIT-

There is one Magento install installed on adomain.nl - there are multiple stores set up with different domains pointing to them. So mydomain.nl is technically adomain.nl/mydomain as a second store in Magento itself. I want to point mydomain.nl/nl/ anything towards mydomain.nl/fnl/ whichever page was requested . In the .htaccess I need to specify that I only want this to be done on mydomain.nl and not a domain.nl

I hope this clears things up - it's quite complicated.

Remove leading slash:

RewriteCond %{HTTP_HOST} !^(www\.)?adomain\.nl$ [NC]
RewriteRule ^nl/(terms-and-conditions-of-use)/ /fnl/$1/ [NC,L,R]

Or making it more generic:

RewriteCond %{HTTP_HOST} !^(www\.)?adomain\.nl$ [NC]
RewriteRule ^nl/(.+) /fnl/$1 [NC,L,R]

Even though anubhava's answer is similiar this worked for me:

RewriteCond %{HTTP_HOST} ^domain\.nl$ [NC]
RewriteRule ^nl/terms-and-conditions-of-use/ /fnl/terms-and-conditions-of-use/ [NC,L,R]

Simply redirects anyone who visits http://domain.nl/nl/terms-and-conditions-of-use/ to http://domain.nl/fnl/terms-and-conditions-of-use and it only does this when the user goes to domain.nl - useful for Magento multi-store sites using only one .htaccess file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM