我有一个的.htaccess
的规则是这样的:
I've got an .htaccess
rule like this:
RewriteRule ^z/([^/]+)$ y.html?$1 [NC,L]
此规则正常工作。但是,如果我改变规则略有下降,为:
This rule works fine. But if I change the rule slightly, to:
RewriteRule ^y/([^/]+)$ y.html?$1 [NC,L]
当我尝试加载 Y /什么
,我收到了404,并在错误日志以下消息:
When I try to load y/anything
I get a 404 and the following message in the error log:
File does not exist: /var/www/y.html/anything
我能看到的唯一区别是, z.html
不存在,但 y.html
一样。起初我想,也许最初的变换被触发递归重新写的,但我看不出这可能是。它应该重写:
The only difference I can see is that z.html
does not exist, but y.html
does. At first I thought maybe the initial transform was triggering a recursive re-write, but I don't see how this could be. It should rewrite:
`y/anything`
到
`y.html?anything`
不具有在它斜线。事实上,与重新编写URL唯一的问题是,它已经在那里我指定一个问号的斜线。这是怎么回事吗?
Which does NOT have a slash in it. In fact, the only problem with the re-written URL is that it has a slash where I specified a question mark. What is going on here?
它变得陌生。如果我改变重写URL,例如以
It gets stranger. If I change the rewrite URL, e.g. to
RewriteRule ^y/([^/]+)$ /q.html?$1 [NC,L]
它仍然告诉我 /var/www/y.html/anything
没有发现,没有q.html ..
it STILL is telling me /var/www/y.html/anything
not found, not q.html..
如果我移动 y.html
到 y.js
在服务器上,然后它告诉我, /var/www/y.js/anything
未找到。这真的好像它是某种匹配 / DIR /
,并改变现有文件。有没有什么地方一个默认的规则,在Apache中可能做到这一点?
If I move y.html
to y.js
on the server, then it tells me /var/www/y.js/anything
is not found. It really seems like it is somehow matching /dir/
and changing it to an existing file. Is there a default rule somewhere in apache that might do this?
我尝试了硬重新加载在浏览器中,这是没有效果的。
I tried a hard reload in the browser, which had no effect.
更新:我试图用 RewriteLog
看到与重新编写了事情的原委。然而,要做到这一点,我不得不将我重写条目我的主要配置的虚拟主机
部分。当我这样做的模式匹配完全停止,直到我改变了我的规则:
Update: I tried to use RewriteLog
to see what was going on with the re-writing. However, to do this I had move my rewrite entries to the VirtualHost
section of my main config. After I did this the pattern matching completely stopped until I changed my rule to:
RewriteRule ^/y/([^/]+)$ /y.html?$1 [NC,L]
进行此更改后,一切都按预期工作。那么,为什么我不能得到它在.htaccess文件中工作?无论是正则表达式工作正常有(带或不带斜线)。
After making this change, everything works as expected. So why can't I get it to work in the .htaccess file? Neither regex works properly there (with or without the leading slash).
对于任何人谁跑入在未来的这个问题,我是有这个问题是多视图干扰了我的URL解析。位置/>当我为&LT选项的列表中删除多视图
在<虚拟主机>
这个问题就走了。
For anyone who runs into this problem in the future, the issue I was having was that MultiViews was interfering with my URL resolution. When I removed "MultiViews" from the list of options for the <Location/>
in the <VirtualHost>
the issue went away.