1

I'm trying to set ErrorDocument 404 page by using ErrorDocument 404 /404.php, but it does not work, because I have mod_rewrite enabled... Is there some chance to check, if the page exist before it falls to mod_rewrite? I'm posting my htaccess down bellow... It is caused by last rule, which redirects everything to 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]

Is there anything I can do with that?

1 Answer 1

1

There is another way in which you can do this. You set the 404 via a RewriteRule and then set the ErrorDocument via URL instead of the file:

RewriteRule ^404/?$ 404.php
ErrorDocument 404 https://www.example.com/404.php

Place it below your last rule and remove the [L] flag from your last rule.

This method shouldn't cause an issue with mod_rewrite. Make sure you clear your cache before testing this.

EDIT

You could just add a condition to the last rule to exclude the 404.php page?

RewriteCond %{REQUEST_URI} !^/404.php

That would stop the Rewrite from happening for that page, so your code would be:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/404.php
RewriteRule ^(.+?)/?$ product.php?url=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your answer, but it still dont work... Posting below edited last lines... RewriteRule ^(.+?)/?$ product.php?url=$1 [QSA] RewriteRule ^404/?$ 404.php ErrorDocument 404 https://ecobamboo.cz/404.php ... is it done correctly?
It is, perhaps just try using the ErrorDocument 404 /404.php, but once again posted below the last rule and with the [L] flag removed. The L flag stands for LAST and stops other rules running past it. Which is why I feel that might be part of the problem.
Infact, see my edit @stepik21 - that should fix your problem and allow you to keep the ErrorDocument 404 /404.php that you had originally :)
would it be possible to hit you up on some chat please? :) I'm still having problems with that... Thanks a million for helping me out!
Sure, no problem. I've created a chat room for us to continue talking about this. Enter it here. Just fyi, I am at work so my responses will be intermittent :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.