1

我创建了一个 .htacces 文件,它执行以下操作:

  • 重定向//.index/(在地址栏中可见)

    或者

  • 重定向/hu/en/.index/hu/.index/en(在地址栏中可见)

然后

  • 将请求重定向/.[p]/[l]/index.php?page=[p]&lang=[l](在地址栏中不可见)

但..

我想在最后保留查询字符串,这意味着访问/.[p]/[l]?a=b结果会导致请求/index.php?page=[p]&lang=[l]&a=b

我似乎无法让正则表达式为此工作。这是整个 .htaccess 文件:

RewriteEngine On
RewriteBase /Main/djdavid98/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(hu|en)?(\/?(\?(([\S]+\=[\S]+)*))?)?$ ./.index/$1$3 [R=301,L]
RewriteRule ^\.([\w\d]+)(\/(hu|en))?\/?(\?(([\S]*=[\S]*)+))?$ index.php?page=$1&lang=$3&$5
4

1 回答 1

1

Use the QSA flag for RewriteRule which will append any query string that's already there to the end of the one you've constructed in your rule's target:

RewriteRule ^\.([\w\d]+)(\/(hu|en))?\/?(\?(([\S]*=[\S]*)+))?$ index.php?page=$1&lang=$3&$5 [L,QSA]

Note that query strings get appended to the end automatically, except when you've constructed your own in your rule's target. That's why the first rule will preserve the query string, but the second rule won't.

于 2013-07-10T23:16:44.767 回答