简体   繁体   English

如何禁用htaccess 404重定向?

[英]how to disable htaccess 404 redirection?

i have a website that is built in PHP, i am using HTACCESS file to hide the .PHP extention from the users, Now im trying to builg a blog in www.sitename.com/blog, i have created the folder and uploaded the files there. 我有一个用PHP构建的网站,我正在使用HTACCESS文件对用户隐藏.PHP扩展,现在我试图在www.sitename.com/blog中建立一个博客,我已经创建了文件夹并上传了文件那里。 The problem is that when i try to access /blog it redirects me to 404. is there anyway to fix this? 问题是,当我尝试访问/ blog时,它会将我重定向到404。是否有解决此问题的方法?

my HTACCESS content is 我的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]

Your Rewrite condition only checks for file: 您的重写条件仅检查文件:

RewriteCond %{REQUEST_FILENAME} !-f

"blog" is a directory, so this won't match and apache will try to open "blog.php", which doesn't exist. “ blog”是一个目录,因此将不匹配,并且apache将尝试打开“ blog.php”,该目录不存在。

Change this line to this: 将此行更改为此:

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

This will check for directories as well. 这还将检查目录。

You should check for existence for .php file before adding .php in the request URI: 在请求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 It should work. DirectoryIndex 404.php它应该工作。 Or: DirectoryIndex 404.php index.php3 messagebrd.pl index.html index.htm Second code is better. 或者:DirectoryIndex 404.php index.php3 messagebrd.pl index.html index.htm第二个代码更好。 If 404.php not work or its no deleted you redirect to index.php3. 如果404.php无法正常工作或没有删除,请重定向至index.php3。

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

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