htaccess RewriteCond REQUEST_URI 检测不起作用 [英] htaccess RewriteCond REQUEST_URI detection not working

查看:51
本文介绍了htaccess RewriteCond REQUEST_URI 检测不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于两种不同类型的 URI,我有两种不同的事情想要发生,但我似乎无法阻止第二种情况在第一种情况已被接受的情况下执行.

这是一个例子:

abc.comabc.com/asdfabc.com/en/asdfabc.com/zh-cn/asdf/asdf

都应该指向这个 RewriteRule:

RewriteRule ^(([az]{2})(-[az]{2})?)(/([a-z0-9-\./]*))?$/index.php?lng=$1&tpl=$4 [QSA,L,NC]

第 2 部分:

abc.com/myadmin/abc.com/myadmin/asdfabc.com/myadmin/en/asdfabc.com/myadmin/zh-cn/asdf/asdf

都应该指向这个 RewriteRule:

RewriteRule ^myadmin/(([az]{2})(-[az]{2})?)(/([a-z0-9-\./]*))?$/myadmin/index.php?lng=$1&tpl=$4 [QSA,L,NC]

我一直试图实现这一点的方法是通过堆叠这样的条件:

RewriteCond %{REQUEST_URI} !^/myadmin/重写规则 ^(([az]{2})(-[az]{2})?)(/([a-z0-9-\./]*))?$/index.php?lng=$1&tpl=$4 [QSA,L,NC]RewriteCond %{REQUEST_URI} ^/myadmin/RewriteRule ^myadmin/(([az]{2})(-[az]{2})?)(/([a-z0-9-\./]*))?$/myadmin/index.php?vlng=$1&tpl=$4 [QSA,L,NC]

但无论我做什么,这两条规则仍然执行.也许我这样做是正确的,并且次要执行发生在 php 模板的更下方,我不确定.我只需要知道我到目前为止所做的一切是否看起来不错.

解决方案

好的,我发现了问题,部分原因是我假设 Chrome 浏览器中的清除缓存扩展 仅适用于单个一个选项卡,该扩展程序中的默认设置在扩展程序激活后自动重新加载所有选项卡.

与大多数开发人员一样,在开发访问我网站的测试区域、开发工具和技术资源时,我在任何给定时刻都会在浏览器中打开 5-10 个选项卡.当我处理代码时,我通常亲自手动完成所有缓存清理工作,以便我知道它真的完成了,在这种情况下,我选择向我的 Chrome 浏览器添加一个名为清除缓存"的新扩展程序来帮助我解决这个问题快一点,因为我做了很多小改动,我需要每次都做干净的测试.我没有意识到的是,当您激活扩展程序时,它还会清除所有其他选项卡的缓存.我也没有注意到默认设置是在执行清洁后自动重新加载它们.因为它也没有向您显示它正在重新加载所有这些其他标签,所以我不知道它正在重新加载我打开的一个标签,该标签是我打开的网站主页,负责加载 cookie.

总结一下,当我在我的网站上工作时,在一个选项卡中,测试对我的管理区域的更改,我一直看到 cookie 更新,这些更新只能来自我网站的公共端,这让我一直认为仍有问题我的 htaccess 发生了变化.我意识到,经过两天的故障排除后,我添加的方便的花花公子扩展程序实际上是在不通知我的情况下重新加载浏览器中的所有选项卡,并且所有其他调用都负责不断返回 cookie只能由我网站的公共端生成,这让我很困惑.在此之后,我将再次手动清除缓存.

I have two different things I want to happen in the case of two different types of URI's but I can't seem to stop the second case from executing where the first case has already been accepted.

Here's an example:

abc.com
abc.com/asdf
abc.com/en/asdf
abc.com/zh-cn/asdf/asdf

Should all be directed to this RewriteRule:

RewriteRule ^(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /index.php?lng=$1&tpl=$4 [QSA,L,NC]

Part 2:

abc.com/myadmin/
abc.com/myadmin/asdf
abc.com/myadmin/en/asdf
abc.com/myadmin/zh-cn/asdf/asdf

Should all be directed to this RewriteRule:

RewriteRule ^myadmin/(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /myadmin/index.php?lng=$1&tpl=$4 [QSA,L,NC]

The way I've been attempting to acheive this is by stacking the conditions like this:

RewriteCond %{REQUEST_URI} !^/myadmin/
RewriteRule ^(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /index.php?lng=$1&tpl=$4 [QSA,L,NC]

RewriteCond %{REQUEST_URI} ^/myadmin/
RewriteRule ^myadmin/(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /myadmin/index.php?vlng=$1&tpl=$4 [QSA,L,NC]

But no matter what I do, both rules still execute. Maybe I'm doing this right and the secondary execute is occurring further down in the php templates, I'm not sure. I just need to know if what I have done so far looks good, ty all.

解决方案

Ok I found the problem, it was partly my fault for assuming the Clear Cache extension in my Chrome browser only worked on a single tab at a time and a default setting in that extension that automatically reload all tabs after the extension was activated.

Like most developers I have between 5-10 tabs open in my browser at any given moment while developing to access testing areas of my site, development tools and technical resources. When I work on code I generally do all my cache cleaning by hand personally so that I know it is really done, in this case I chose to add a new extension to my Chrome browser called 'Clear Cache' to help me take care of this a little faster because I was making a lot of small changes which I needed to make clean tests of each time. What I didn't realise was that when you activate the extension it also cleans the cache of all your other tabs as well. I also didn't notice the default setting that is set to automatically reload them all after the cleaning is performed. Because it also doesn't show you that it is reloading all these other tabs visually I had no idea it was reloading a tab that I had open to the main page of the site I was working on that was responsible for loading cookies.

To summarize while I worked on my site, in one tab, testing changes to my admin area I kept seeing cookie updates that could only come from the public side of my site and it kept making me think there was something still wrong with my htaccess changes. I realized, after two days of troubleshooting, the handy dandy extension I'd added to help make things easier was actually reloading all the tabs in my browser without letting me know and all those other calls were responsible for the continual return of cookies that could only be generated by the public side of my site which was confusing the hell out of me. I'll be going to go back to clearing my cache by hand again after this.

这篇关于htaccess RewriteCond REQUEST_URI 检测不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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