简体   繁体   中英

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. The problem is that when i try to access /blog it redirects me to 404. is there anyway to fix this?

my HTACCESS content is

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

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:

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. Or: DirectoryIndex 404.php index.php3 messagebrd.pl index.html index.htm Second code is better. If 404.php not work or its no deleted you redirect to index.php3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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