简体   繁体   English

使用RewriteCond和RewriteRule重定向一页

[英]Using RewriteCond and RewriteRule to redirect one page

When a user navigates to http://mydomain.nl/nl/my-page/ 当用户导航到http://mydomain.nl/nl/my-page/

I need the user to be redirected to http://mydomain.nl/fnl/my-page/ 我需要将用户重定向到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. 这是因为我正在使用的网站是一个多商店多语言的Magento网上商店,该商店被我之前的某个人错误地配置,因此每种语言都有自己的商店范围,而不是每个商店都有自己的语言范围。

I have the following code in my .htaccess : 我的.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. 基本上,我假设这样做是检查它是否在正确的域(即mydomain.nl)上,然后重定向URL,以便用户看到正确的页面。

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) 如果单击它,它将带我回到主域的主页(然后是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. 在adomain.nl上安装了一个Magento安装-有多个商店设置了指向它们的不同域。 So mydomain.nl is technically adomain.nl/mydomain as a second store in Magento itself. 因此,mydomain.nl在技术上是adomain.nl/mydomain,作为Magento本身的第二个存储。 I want to point mydomain.nl/nl/ anything towards mydomain.nl/fnl/ whichever page was requested . 我想指出mydomain.nl/nl/对mydomain.nl/fnl/ 什么 取其被请求的页面 In the .htaccess I need to specify that I only want this to be done on mydomain.nl and not a domain.nl 在.htaccess中,我需要指定仅希望在mydomain.nl而不是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: 即使anubhava的回答很相似,这也对我有用:

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. 只需将访问http://domain.nl/nl/terms-and-conditions-of-use/的任何人重定向到http://domain.nl/fnl/terms-and-conditions-of-use ,它只会执行此操作当用户转到domain.nl时-对于仅使用一个.htaccess文件的Magento多店站点很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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