[英]override apache rewrite rules with htaccess
working on a server that hosts multiple domains. 在承载多个域的服务器上工作。 Somewhere in apache config is a rewrite rule that is set for ALL domains.
在apache config中的某处是为所有域设置的重写规则。
What happens is if a user goes to example.com/foo they are supposed to get redirected to example.com/foo_bar 发生的情况是,如果用户转到example.com/foo,则应该将他们重定向到example.com/foo_bar
However, in one domain, I want to override this behavior so that the url stays at example.com/foo and does not redirect. 但是,在一个域中,我想覆盖此行为,以便url保持在example.com/foo且不重定向。 I've been searching and trying various rules and conditions to no avail.
我一直在搜索并尝试各种规则和条件都无济于事。 I don't have access to the apache config, but I am using .htaccess for some rewrite rules on this domain.
我无权访问apache配置,但是我在此域上使用.htaccess进行一些重写规则。
here's my rewrite rules in .htaccess: 这是我在.htaccess中的重写规则:
<IfModule mod_rewrite.c>
RewriteEngine on
# this isn't working
# RewriteRule ^(foo)($|/) - [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1
# this didn't work either
# RewriteRule ^/foo index.php?/$1 [L]
</IfModule>
Try redirecting /foo_bar
back to /foo
. 尝试将
/foo_bar
重定向回/foo
。
When Apache processes the rewrite rules it runs through them multiple times, which you can see when you turn on debugging . 当Apache处理重写规则时,它会多次运行它们,您可以在打开debug时看到这些规则。 I think what's happening in your case is that you're trying to match the URI in the first pass, but Apache has already modified it to
/foo_bar
. 我认为您遇到的情况是您试图在第一遍中匹配URI,但是Apache已将其修改为
/foo_bar
。
Also, as a matter of debugging, you should try to recreate the problem in an environment you control. 另外,作为调试的问题,您应该尝试在您控制的环境中重新创建问题。 Ask your sysadmin for a copy of the global configuration and mirror the set up you're constrained to.
向您的系统管理员询问全局配置的副本,并镜像您要约束的设置。
You can create exception for one domain: 您可以为一个域创建例外:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(?:www\.)?domain\.com$ [NC]
RewriteRule ^foo(/.*)?$ /foo_bar$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.