.htaccess的URLRewrite到其他地图 [英] Htaccess URLRewrite to another map

查看:154
本文介绍了.htaccess的URLRewrite到其他地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我去{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]

这篇关于.htaccess的URLRewrite到其他地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆