使用htaccess用变量重写url?

时间:2015-03-30 06:38:12

标签: php .htaccess

使用htaccess如何代替以下内容来实现

http://domain.com/verify

http://domain.com/verify?user=_FIRST-VARIABLE_&verification_code=_SECOND-VARIABLE_

这是原始的

http://domain.com/account/index.php?user=_FIRST-VARIABLE_&verification_code=_SECOND-VARIABLE_

我目前的htaccess是

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^login$ account/index.php [NC]
RewriteRule ^register$ account/index.php?register [NC]
RewriteRule ^([^\.]+)$ $1.php [NC,L]

1 个答案:

答案 0 :(得分:0)

尝试使用正则表达式模式的RewriteRule

  RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^varify/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$/account/index.php?foo=$1&bar=$2 [NC,QSA,L]
  

使用变量更改变量foo和bar。

对example.com/varify/var1/var2的所有请求都将重定向到example.com/account/index.php?foo=$1&bar=$2