我正在尝试通过使用ErrorDocument 404 /404.php
来设置ErrorDocument 404页面,但是它不起作用,因为我启用了mod_rewrite ...是否有机会检查页面是否存在,直到它掉到mod_rewrite之前?我将htaccess发布到下面...这是由上一条规则引起的,该规则将所有内容重定向到product.php-RewriteRule ^(.+?)/?$ product.php?url=$1 [L,QSA]
DirectoryIndex index.php
RewriteEngine On
ErrorDocument 404 /404.php
RewriteRule ^(admin|subdom)($|/) - [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^coming-soon/?$ coming-soon.php [L]
RewriteRule ^tabulky-velikosti/?$ tabulky-velikosti.php [L]
RewriteRule ^o-bambusu/?$ o-bambusu.php [L]
RewriteRule ^vymena-zbozi/?$ vymena-zbozi.php [L]
RewriteRule ^doprava-a-platba/?$ doprava-a-platba.php [L]
RewriteRule ^obchodni-podminky/?$ obchodni-podminky.php [L]
RewriteRule ^ochrana-osobnich-udaju/?$ ochrana-osobnich-udaju.php [L]
RewriteRule ^o-nas/?$ onas.php [L]
RewriteRule ^kontakt/?$ kontakt.php [L]
RewriteRule ^faq/?$ faq.php [L]
RewriteRule ^kosik/?$ cart.php [L]
RewriteRule ^blog/?$ blog.php [L]
RewriteRule ^search/?$ search.php [L]
RewriteRule ^blog/tag/(.*)/? blog.php?tag=$1 [L,QSA]
RewriteRule ^blog/(.*)/? blogDetail.php?url=$1 [L,QSA]
RewriteRule ^search/(.*)/? search.php?s=$1 [L,QSA]
RewriteRule ^zaciname/?$ category.php [L]
RewriteRule ^nakupovat/?$ category.php [L]
RewriteRule ^kategorie/?$ category.php [L]
RewriteRule ^prozkoumat/?$ category.php [L]
RewriteRule ^kategorie/((?:pan|dam|det)ske)-pradlo/?$ category.php?gender=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ product.php?url=$1 [L,QSA]
我能做些什么吗?
答案 0 :(得分:1)
还有另一种方法可以执行此操作。您可以通过RewriteRule
设置404,然后通过URL而不是文件来设置ErrorDocument
:
RewriteRule ^404/?$ 404.php
ErrorDocument 404 https://www.example.com/404.php
将其放在您的最后一条规则下方,然后从您的最后一条规则中删除[L]
标志。
此方法不应导致mod_rewrite
出现问题。在进行测试之前,请确保 清除缓存。
编辑
您可以只在最后一条规则中添加一个条件以排除404.php
页吗?
RewriteCond %{REQUEST_URI} !^/404.php
那将阻止该页面发生重写,因此您的代码将是:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/404.php
RewriteRule ^(.+?)/?$ product.php?url=$1 [L,QSA]