简体   繁体   English

当url字符串是现有文件的名称时,mod_rewrite不起作用

[英]mod_rewrite not working when url string is the name of an existing file

What I want to do is to remove the php file extension needed for the url, 我想要做的是删除网址所需的php文件扩展名,

ie myipaddress/abc -> myipaddress/abc.php 即myipaddress / abc-> myipaddress / abc.php

However I can't seem to get mod_rewrite to work using the solutions in this link . 但是我似乎无法使用此链接中的解决方案使mod_rewrite正常工作。

My .htaccess file contains these lines: 我的.htaccess文件包含以下几行:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1c.php [L]

So if i have a file named abc.php on my server and my url in the browser is "myipaddress/ab", abc.php will be properly shown. 因此,如果我在服务器上有一个名为abc.php的文件,并且浏览器中的URL是“ myipaddress / ab”,则将正确显示abc.php。 Any file that cannot be found will return me a internal server error (since the third cond is commented out). 找不到任何文件都将返回内部服务器错误(因为第三个条件已被注释掉)。

In this case i get this to work: 在这种情况下,我可以使用它:

myipaddress/ab -> myipaddress/abc.php myipaddress / ab-> myipaddress / abc.php

Now if i change the last line like this (which is the answer provided): 现在,如果我像这样更改最后一行(提供的答案):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

Now if I have a file named abc.php and i put in myipaddress/abc, i get a 404 not found which says 现在,如果我有一个名为abc.php的文件,并将其放在myipaddress / abc中,则会显示未找到的404信息,

Not Found

The requested URL /abc was not found on this server.

If i look up for other links like abcd.php which is not on my server, i still get a 500 internal server error. 如果我查找服务器上没有的其他链接(如abcd.php),则仍然会收到500个内部服务器错误。 However when i try a link like myipaddress/name and if name.php is on my server, i get a 404. I'm very confused by the fact that if the url contains name, mod_rewrite will not rewrite the url and have spent hours on it. 但是,当我尝试使用myipaddress / name之类的链接并且如果name.php在我的服务器上时,我得到404。如果URL包含名称,mod_rewrite不会重写URL并花费了数小时,这一事实让我感到困惑在上面。 Can anyone help? 有人可以帮忙吗?

Sounds like you have automatic content negotiation enabled on your system. 听起来您的系统上启用了自动内容协商。 You want to disable it. 您要禁用它。

Take a look into the documentation. 查看文档。 It is well written and comes with lots of great examples: 它写得很好,并带有很多很好的例子:

http://httpd.apache.org/docs/current/content-negotiation.html http://httpd.apache.org/docs/current/content-negotiation.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM