簡體   English   中英

Apache2-mod_rewrite和.htacess-當我添加其他規則時無法使用404規則

[英]Apache2 - mod_rewrite and .htacess - Not working 404 rule when i add other rules

這是我當前的.htaccess文件:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php\s 
RewriteRule .* %1.html [R=301,L]
RewriteRule ^(.*)\.html$ $1.php 

ErrorDocument 404 /page-404.html 

像這樣,當我打開以.php結尾的地址時,它會自動重定向到相同的地址,但是像我想要的那樣以.html結尾。

當我刪除這些行時:

RewriteEngine On

ErrorDocument 404 /page-404.html 

而且我嘗試打開不存在的目錄,我將404錯誤重定向到我想要的頁面。 當我添加我發布的第一個代碼中顯示的其他行時,問題就來了。

問題出在哪里?為什么在我的第一個示例中404錯誤重定向不起作用?

提前致謝!

有這樣的規則:

ErrorDocument 404 /page-404.html
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php\s [NC]
RewriteRule .* %1.html [R=301,L]

# make sure .php file exists for the requested .html file
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM