Php 如何禁用htaccess 404重定向?

Php 如何禁用htaccess 404重定向?,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我有一个用PHP构建的网站,我正在使用HTACCESS文件对用户隐藏.PHP扩展名,现在我正试图在www.sitename.com/blog中创建一个博客,我已经创建了文件夹并将文件上传到那里。问题是,当我尝试访问/blog时,它会将我重定向到404。有没有办法解决这个问题 我的HTACCESS内容是 <IfModule mod_deflate.c> #The following line is enough for .js and .css AddOutputFil

我有一个用PHP构建的网站,我正在使用HTACCESS文件对用户隐藏.PHP扩展名,现在我正试图在www.sitename.com/blog中创建一个博客,我已经创建了文件夹并将文件上传到那里。问题是,当我尝试访问/blog时,它会将我重定向到404。有没有办法解决这个问题

我的HTACCESS内容是

<IfModule mod_deflate.c>
    #The following line is enough for .js and .css
    AddOutputFilter DEFLATE js css

    #The following line also enables compression by file content type, for the following list of Content-Type:s
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml

    #The following lines are to avoid bugs with some browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
</IfModule>

<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>

ErrorDocument 404 /404.php

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteCond %{HTTP_HOST} ^www\.vartag\.com$ [NC]
RewriteRule (.*) http://vartag.com/$1 [R=301,L]

#下面的行对于.js和.css已经足够了
AddOutputFilter DEFLATE js css
#下一行还支持按文件内容类型对以下内容类型列表进行压缩:s
AddOutputFilterByType DEFLATE text/html text/plain text/xml应用程序/xml
#以下几行是为了避免某些浏览器出现bug
浏览器匹配^Mozilla/4 gzip纯文本/html
浏览器匹配^Mozilla/4\.0[678]无gzip
BrowserMatch\bMSIE!没有gzip!仅限gzip文本/html
标题集连接保持活动状态
ErrorDocument 404/404.php
mod_gzip_on Yes
是的
mod|gzip|item|u include file.(html?| txt | css | js | php | pl)$
mod_gzip_item_包含处理程序^cgi脚本$
mod_gzip_项目包括mime^text/*
mod_gzip_item_包括mime^application/x-javascript*
mod_gzip_项_排除mime^image/*
mod_gzip_item_排除rspheader^内容编码:.*gzip*
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写规则^([^\.]+)$$1.php[NC,L]
重写cond%{HTTP_HOST}^www\.vartag\.com$[NC]
重写规则(.*)http://vartag.com/$1[R=301,L]

您的重写条件仅检查文件:

RewriteCond %{REQUEST_FILENAME} !-f
“blog”是一个目录,所以这不匹配,apache将尝试打开“blog.php”,它不存在

将此行更改为:

RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d

这也将检查目录。

在请求URI中添加
.php
之前,您应该检查
.php
文件是否存在:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(vartag\.com)$ [NC]
RewriteRule (.*) http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]