.htaccess和URL路由的问题

时间:2017-05-28 06:58:47

标签: php apache .htaccess mod-rewrite url-routing

我写了这个.htaccess规则:

RewriteRule ^([a-zA-Z]*)([a-zA-Z0-9\/\-_\#]+)\.?([a-zA-Z]+)?$ index.php?lang=$1&url=$2&extension=$3 [QSA,L]

我希望通过这样的方式实现这一目标:mydomain.com/en/account/settings.html,其中'en'是当前的工作语言,'account'是控制器等;它应该以这种形式分离和重定向:index.php?lang = en& url = account / settings& extension = html,这是完美的。 但是当请求看起来就像没有最后一个斜杠的mydomain.com/时,它会失败并使控制器名称如下所示:NController,通过选择'en'中的最后一个'n'来表示语言并将其添加到url当url应该没有值时。现在我想要的是,如果没有请求控制器,当uri以'或'结尾时,如果没有最后一个斜杠,则url保持为空。

有了这样的uri http://localhost/application/en/
这就是我得到的Array ( [lang] => en [url] => / [extension] => )

但是这样:http://localhost/application/en 我得到了这个:Array ( [lang] => e [url] => n [extension] => )

但我想要的是Array ( [lang] => en [url] => [extension] => ),无论是http://localhost/application/en还是http://localhost/application/en/ 我该怎么办?

0 个答案:

没有答案