.htaccess RewriteRule用于隐藏和可见的GET

pnm*_*123 4 .htaccess mod-rewrite url-rewriting

这就是我已经做过的事情.

RewriteRule ^([a-z]+)$ index.php?file=$1
Run Code Online (Sandbox Code Playgroud)

所以当访问domain.com/browse它实际上读domain.com/index.php?file=browse

但问题是,这不会传递这样的可见GET变量:domain.com/browse?page=2.如何让它传递两个GET变量:domain.com/index.php?file=browse&page=2.

任何帮助,将不胜感激!

Boo*_*eus 10

你可以用这个:

RewriteRule ^browse/?$ index.php?file=browse&page=1 [L,NC,QSA]
RewriteRule ^browse/([0-9]+)/?$ index.php?file=browse&page=$1 [L,NC,QSA]

#else it's for files
RewriteRule ^([a-z]+)/?$ index.php?file=$1 [L,NC,QSA]
Run Code Online (Sandbox Code Playgroud)

或使用:

RewriteRule ^([a-z]+)$ php.php?file=$1 [L,NC,QSA]
Run Code Online (Sandbox Code Playgroud)

QSA(查询字符串追加)标志将允许传递_GET变量


Tch*_*upi 7

您必须在重写中显式添加查询字符串:

RewriteRule ^([a-z]+)$ index.php?file=$1&%{QUERY_STRING}
Run Code Online (Sandbox Code Playgroud)