Htaccess URLRewrite to another map

ぃ、小莉子 提交于 2019-12-11 16:26:44

问题


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!


回答1:


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]


来源:https://stackoverflow.com/questions/12442962/htaccess-urlrewrite-to-another-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!