使用mod_rewrite匹配查询字符串变量?

时间:2014-05-04 09:47:14

标签: .htaccess mod-rewrite query-string

我正在尝试处理的网站是http://northidahocvma.org/2GD/index.php?page=1

假设我有带有查询字符串参数的URL,如下所示:

/index.php?page=1

使用mod_rewrite,如何将它们重定向到这些URL?

/page/1/1/

我得到了这段代码,但仍然无法弄清楚

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [R=302,L]

RewriteRule ^page/([^/.]+)/?$ /index.php?page=$1 [L,QSA,NC]

1 个答案:

答案 0 :(得分:0)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [R=302,L]

RewriteRule ^page/([^/.]+)/?$ /index.php?page=$1 [L,QSA,NC]