Pergunta

I was wondering if there is a way to use Mod Rewrite to handle every possible http status error code (4XX and 5XX ones) instead of declaring them all in htaccess like this:

# serve custom error pages
ErrorDocument 400 error.php?code=400
[...]
ErrorDocument 510 error.php?code=510

Somewhere around I found this little trick:

# provide a universal error document
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ error.php [L]

But isn't it handling only 404 ones? If it's ok, how can I modify my cache busting rewrite rule to also make it handle this feature?

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.\d+\.(css|js)$ $1.$2 [L]

I would need something like:

IF %{REQUEST_URI} MATCHES "^(.+)\.\d+\.(css|js)$"
    REWRITE TO "$1.$2"
ELSE
    REWRITE TO "error.php"

Can you help me please? Many thanks!

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top