andre andre - 2 months ago 4
PHP Question

Error 404 page and htacess issues

First of all, thank you for those who might help me with this issue! :)

What is going on is the following: I have a client which requested me to created a custom 404 error page (for SEO purposes), here follows his website: (site) (404 path working) (trying to reproduce the 404 error, nothing happens) (Error 500 happening):

Internal Server Error: The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Here follows the htaccess file:

AddDefaultCharset ISO-8859-1


Options -Indexes

#Habilita o Módulo de Reescrita
RewriteEngine On

#Se a URL apontar para um arquivo, vai diretamente para ele
RewriteCond %{REQUEST_FILENAME} !-f
#Se a URL apontar para uma pasta, vai diretamente para ela
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?(.*)$ $1/index.php?id=$2&pg=$3&sub=$4&aux1=$5&aux2=$6&aux3=$7&aux4=$8

#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

ErrorDocument 404 /erros/404.html

Any Idea how to solve this issue?

The error page 404 works if I remove the following:

RewriteRule ^([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?(.*)$ $1/index.php?id=$2&pg=$3&sub=$4&aux1=$5&aux2=$6&aux3=$7&aux4=$8


First, most likely, you have this error because you haven't set flag [L]. So, replace:

RewriteRule ^([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?(.*)$ $1/index.php?id=$2&pg=$3&sub=$4&aux1=$5&aux2=$6&aux3=$7&aux4=$8


RewriteRule ^([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?(.*)$ $1/index.php?id=$2&pg=$3&sub=$4&aux1=$5&aux2=$6&aux3=$7&aux4=$8 [L]

(I've added [L] to the end of this string).

And notice, that only one string under RewriteCond will be executed. So, when you removed RewriteRule you get your ErrorDocument working.