Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache mod_重写以删除.html扩展不起作用_Apache_Mod Rewrite - Fatal编程技术网

Apache mod_重写以删除.html扩展不起作用

Apache mod_重写以删除.html扩展不起作用,apache,mod-rewrite,Apache,Mod Rewrite,我知道这将是一件愚蠢的事情,但在过去的几个小时里,我一直在努力想办法解决这个问题。我根本无法获得新的Apache2.4安装来查找url mysite.com/signup(其中signup.html)的存在 如果我导航到mysite.com/signup.html,一切正常。但是如果我导航到mysite.com/signup,我会得到一个404 以下是我正在使用的重写 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENA

我知道这将是一件愚蠢的事情,但在过去的几个小时里,我一直在努力想办法解决这个问题。我根本无法获得新的Apache2.4安装来查找url mysite.com/signup(其中signup.html)的存在

如果我导航到mysite.com/signup.html,一切正常。但是如果我导航到mysite.com/signup,我会得到一个404

以下是我正在使用的重写

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule (.*)  $1.html [L]
下面是调试重写的结果

[rewrite:trace3] applying pattern '(.*)' to uri '/signup'
[rewrite:trace4] RewriteCond: input='/signup' pattern='!-d' => matched
[rewrite:trace4] RewriteCond: input='/signup' pattern='!-f' => matched
[rewrite:trace4] RewriteCond: input='/signup.html' pattern='-f' => not-matched
[rewrite:trace1] pass through /signup
正如您所看到的,第四个日志输出应该(我相信)是匹配的,因为我可以直接导航到signup.html文件,所以它确实存在

请注意,我直接在vhost的conf文件中进行更改,而不是在htaccess中进行更改

我错过了什么!!! 谢谢 戳一下

试试这个:

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_URI} !\.(htm|html)$

   RewriteRule /([0-9A-Za-z@.]+)$ /$1.html [QSA,R=307] 

谢谢你。这对我来说部分有效。如果我不在URL上使用.html,它会附加它,然后它就会工作。但是,我不希望附加.html,我希望URL简单地说/signup而不是/signup.htmlso,只是注意到这似乎会对其他文件产生负面影响,因为它试图在请求的URL末尾添加.html。(例如图像或其他资源!)如果只想进行一次重写,请不要设置RewriteCond%{REQUEST\u URI}!\。(htm | html)$并且只重写rule/signup$/signup.html[QSA,R=307]