.htaccess的URLRewrite到其他地图地图、htaccess、URLRewrite

由网友(皇后别闹随朕起驾回宫吃药)分享简介:当我去{URL} / klanten /家庭/或{URL} / klanten /注销/ 500内部服务器错误来了。When i go to {url}/klanten/home/ or {url}/klanten/logout/ a 500 Internal Server Error come.我的htacces...

当我去{URL} / klanten /家庭/或{URL} / klanten /注销/ 500内部服务器错误来了。

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

我的htaccess的:

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]

地图klanten'存在,并且该文件home.php和logout.php存在了。

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

谢谢!

推荐答案

这条规则是错误的,它会导致不确定的重定向:

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

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

/ klanten /退出/ 将导致 /klanten/logout.php 这反过来将再次被改写又一遍。

/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]
阅读全文

相关推荐

最新文章