“双向"改写 [英] "Two Way" Rewrite

查看:25
本文介绍了“双向"改写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在努力做到这一点:

我们有一个 URL /brand/new-inventory.php.这是我们网站内的物理文件.我希望它是 /brand/new.现在这很容易.我只需要添加RewriteRule ^brand/new$brand/new-inventory.php [L,QSA].

现在,我想要设置并且我一直在努力的是:<​​/p>

当有人查看时,我们需要 /brand/new-inventory.php 重定向到 /brand/new 以便我们有一致的 URL 和其他内容.>

但是,当我尝试 RewriteRule ^brand/new-inventory.php$ brand/new [R=301,L] 时,Firefox 开始抱怨一个永远不会结束的重定向循环.>

如何重写页面以响应不同的 URL,并将旧 URL 重定向到新 URL?

解决方案

就这样:

RewriteCond %{THE_REQUEST} \s/+brand/new-inventory\.php[/\s?] [NC]重写规则 ^/brand/new [R=302,L]RewriteRule ^brand/new$/brand/new-inventory.php [L,NC]

不同之处在于使用 %{THE_REQUEST} 表示 Apache 从您的浏览器收到的原始请求.此变量的值不会随着其他重写规则的应用而改变.

So, I'm trying to accomplish this:

We have a URL /brand/new-inventory.php. This is a physical file within our site. What I'd like it to be is /brand/new. Now that was easy. All I had to add was RewriteRule ^brand/new$ brand/new-inventory.php [L,QSA].

Now, what I'd like to get setup and I've been struggling with is this:

We need /brand/new-inventory.php when viewed by someone to redirect to /brand/new so we have consistent URL's and what-not.

But, when I try RewriteRule ^brand/new-inventory.php$ brand/new [R=301,L] Firefox starts to complain about a redirect loop that will never end.

How can I rewrite a page to respond to a different URL, and redirect the old URL to the new one?

解决方案

Have it this way:

RewriteCond %{THE_REQUEST} \s/+brand/new-inventory\.php[/\s?] [NC]
RewriteRule ^ /brand/new [R=302,L]

RewriteRule ^brand/new$ /brand/new-inventory.php [L,NC]

Difference is use of %{THE_REQUEST} that represents original request received by Apache from your browser. Value of this variable doesn't change with application of other rewrite rules.

这篇关于“双向"改写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆