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

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

问题描述

所以,我试图做到这一点:

So, I'm trying to accomplish this:

我们有一个网址 /brand/new-inventory.php 。这是我们的网站内的物理文件。 我想它会是 /品牌/新。现在,这很简单。所有我不得不添加了重写规则^品牌/新$品牌/新inventory.php [L,QSA]

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:

我们需要 /brand/new-inventory.php 有人看重定向到 /品牌/新所以我们有一致的网址和什么,而不是。

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

但是,当我尝试重写规则^品牌/新inventory.php $品牌/新[R = 301,L] 火狐开始抱怨重定向循环永远不会结束。

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.

我如何重写一个页面来应对不同的URL,并重定向旧的URL到新的?

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

推荐答案

有这样说道:

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]

不同的是使用%{THE_REQUEST} 收到被Apache重新presents原始请求从您的浏览器。这个变量的值不与应用程序的其他重写规则的改变。

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天全站免登陆