dongqun9403 2017-08-13 08:03
浏览 27
已采纳

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

What I want to do is to remove the php file extension needed for the url,

i.e. myipaddress/abc -> myipaddress/abc.php

However I can't seem to get mod_rewrite to work using the solutions in this link.

My .htaccess file contains these lines:

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. 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

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

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. 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. Can anyone help?

  • 写回答

1条回答 默认 最新

  • doupo2157 2017-08-13 09:26
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答