我的 .htaccess 作業,它做我想要的,但是當我將一個不存在的檔案寫入地址欄時,它給了我 500 內部服務器錯誤,而不是 404 未找到。你能幫我嗎,為什么?
RewriteEngine ON
RewriteCond %{REQUEST_URI} !/?exception\.php [NC]
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteCond %{THE_REQUEST} \s/([^.]*)\.php/?\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ $1.php [QSA,L]
RewriteCond %{THE_REQUEST} \s/new\.php\?article=(\S )\s [NC]
RewriteRule ^ /news/%1? [R=301,L]
RewriteRule ^news/([^/]*)$ new.php?article=$1 [NC,QSA,L]
RewriteCond %{THE_REQUEST} \s/category\.php\?catid=(\S )\s [NC]
RewriteRule ^ /news/categories/%1? [R=301,L]
RewriteRule ^news/categories/([^/]*)$ category.php?catid=$1 [NC,QSA,L]
uj5u.com熱心網友回復:
您的第二條規則似乎是.php為每個不存在的 URI 寫入 a 的罪魁禍首。
您可以在站點根目錄 .htaccess 中嘗試此代碼:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/category\.php\?catid=(\S )\s [NC]
RewriteRule ^ /news/categories/%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/new\.php\?article=(\S )\s [NC]
RewriteRule ^ /news/%1? [R=301,L]
RewriteCond %{REQUEST_URI} !/(exception\.php|admin) [NC]
RewriteCond %{THE_REQUEST} \s/([^.]*)\.php/?\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteRule ^news/categories/([^/]*)$ category.php?catid=$1 [NC,QSA,L]
RewriteRule ^news/([^/]*)$ new.php?article=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(. ?)/?$ $1.php [L]
請注意最后一條規則,該規則.php僅為具有匹配.php檔案的 URI 添加擴展名。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/523398.html
