最后的rewriteRule斜线和改进

时间:2015-09-28 18:10:08

标签: .htaccess mod-rewrite

我有以下规则:

RewriteRule ^news/([^/]*)$ /news.php?lang=$1 [L]

在这里,我可以使用http://domain.tld/news/de访问该网站,但我无法通过http://domain.tld/news/de/(最后反斜杠)与他们联系。

我该怎么做?

第二个问题是如何将这3条规则简化为一条,因为它处理所有相同的页面?

# News
RewriteRule ^news/page/([^/]*)/([^/]*)$ /news.php?page=$1&lang=$2 [L]
RewriteRule ^news/page/([^/]*)$ /news.php?page=$1 [L]
RewriteRule ^news/([^/]*)$ /news.php?lang=$1 [L]

提前致谢。

1 个答案:

答案 0 :(得分:0)

使用可选的尾部斜杠,并可选择关闭MultiViews

Options -MultiViews
RewriteEngine On

RewriteRule ^news/page/([^/]+)/([^/]+)/?$ news.php?page=$1&lang=$2 [L,QSA,NC]
RewriteRule ^news/page/([^/]+)/?$ news.php?page=$1 [L,QSA,NC]
RewriteRule ^news/([^/]+)/?$ news.php?lang=$1 [L,QSA,NC]