[英]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.