Search code examples
php.htaccessdictionaryurl-rewritinginternal

Htaccess URLRewrite to another map


When i go to {url}/klanten/home/ or {url}/klanten/logout/ a 500 Internal Server Error come.

My htaccess:

RewriteEngine on

RewriteRule ^klanten/([^/]+)/?$ klanten/$1.php [L,QSA,NC]

RewriteRule ^error/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ error.php?type=$1&error=$2&file=$3&from=$4 [L,QSA,NC]

RewriteRule ^email/([^/]+)/?$ email.php?id=$1 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

The map 'klanten' exists and the file home.php and logout.php exists too.

Thanks!


Solution

  • This rule is wrong, it leads to an indefinite redirect:

    RewriteRule ^klanten/([^/]+)/?$ klanten/$1.php [L,QSA,NC]
    

    /klanten/logout/ will lead to /klanten/logout.php which in turn will be rewritten again and again.

    You could add the dot to the character class to avoid that so that only urls without a dot get rewritten:

    RewriteRule ^klanten/([^/\.]+)/?$ klanten/$1.php [L,QSA,NC]
    

    or you just add the conditions that existing files and directories do not get rewritten (obviously the better solution...):

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^klanten/([^/]+)/?$ klanten/$1.php [L,QSA,NC]