繁体   English   中英

如何禁用htaccess 404重定向?

[英]how to disable htaccess 404 redirection?

我有一个用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]

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

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]

DirectoryIndex 404.php它应该工作。 或者:DirectoryIndex 404.php index.php3 messagebrd.pl index.html index.htm第二个代码更好。 如果404.php无法正常工作或没有删除,请重定向至index.php3。

暂无
暂无

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

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