问题描述
我正在尝试整理URL,并从中删除.php扩展名.我在网站的基本文件夹中,因此没有可以优先处理的父.htaccess文件.这是我的htaccess代码.
I'm trying to tidy up the URLs and remove the .php extensions from them and such. I'm in the base folder for the website, so there are no parent .htaccess files that could be taking priority or anything. Here's my htaccess code.
RewriteEngine On
RewriteRule ^give/?$ give.php [NC,L]
这部分没有任何实际问题,因为无论什么行为被覆盖,它的行为方式都是相同的.但是,当我在这一行中添加内容时,它将说明url变量,
This part gives no real problems, because whatever behavior is overwriting it behaves the same way. But when I add in this other line so it will account for url variables,
RewriteRule ^give/([0-9]+)/?$ give.php?step=$1 [NC,L]
它完全忽略了它.但是,如果我将give.php重命名为其他名称,那么它与url不匹配,则可以使用.例如,使用give.php使其遵循.htaccess规则.我以前从未遇到过这个问题.有一些我可以更改的服务器设置,所以我不必给我的文件起一个奇怪的名字吗?
It completely ignores it. However, if I rename give.php to anything else, so it doesn't match the url, it works. For example, using given.php causes it to heed the .htaccess rules. I've never run across this issue before. Is there some server setting I can change so I don't have to give my files odd names?
还请注意,我尝试更改第一行以重定向到另一个文件,但未更改实际文件名Give.php.它忽略了我的重定向,仍然加载了Give.php文件.
Also note, I tried changing that first line to redirect to another file, but without changing the actual file name give.php. It ignored my redirect and still loaded the give.php file.
我尝试更改2条规则的顺序,我尝试先注释两个规则,然后注释另一个规则,以查看它们是否相互冲突.据我所知,如果不存在/give/目录,则服务器具有某种默认行为,该行为会将/give/定向到/give.php.因为即使我删除了这两个规则,转到/give/仍会将我重定向到/give.php.只有当我将文件名更改为given.php时,它才会破坏该默认行为.我还尝试将更简单的规则设置为此:
I've tried changing the order of the 2 rules, I've tried commenting both one rule, then the other to see if they are conflicting with eachother. The best I can figure, the server has some sort of default behavior that directs /give/ to /give.php if no directory of /give/ exists. Because even if I remove both rules, going to /give/ still redirects me to /give.php. Only when I change the filename to given.php will it break that default behavior. I also tried setting the simpler rule to this:
RewriteRule ^give/?$ resources.php [NC,L]
只要文件Give.php存在,它仍将重定向到Give.php.如果我删除了Give.php或更改了名称,则转到/give将重定向到resources.php
And as long as the file give.php existed, it still redirected to give.php. If I removed give.php or changed its name, going to /give would then redirect to resources.php
推荐答案
您可能与mod_negotiation
的MultiViews
选项有冲突.您的请求可能根本没有达到RewriteRule
,而是由于mod_negotiation
而由give.php
处理.来自文档:
You may have a conflict with the MultiViews
option of mod_negotiation
. Your request may not be hitting the RewriteRule
at all, and is instead being handled by the give.php
because of mod_negotiation
. From the docs:
尝试将其添加到您的.htaccess
中,看看情况是否有所变化:
Try adding this to your .htaccess
and see if things change:
Options -MultiViews
这篇关于如果文件名减去ext,则.htaccess URL重写行为将被覆盖.与网址相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!