这是我目前的.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?u=$1 [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
将 www.example.com 转换为 example.com 并解释 example.com/username AS example.com/的index.php?U =用户名
现在我想传递第二个参数,例如 example.com/index.php?u=username&e=email ,并保持格式 example.com/arg1&arg2 < / strong>即可。我怎么在.htaccess中做到这一点?
答案 0 :(得分:0)
首先,您需要在路由规则之前移动重定向:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
然后,您要检查2参数路线:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z-]+)/([^/]+)/?$ /index.php?u=$1&e=$2 [L,QSA]
(这假定网址类似于:http://example.com/username/emailaddress
,但如果您确实希望&
将其分开,请改用此规则:
RewriteRule ^([0-9a-zA-Z-]+)&([^/]+)/?$ /index.php?u=$1&e=$2 [L,QSA]
这假定网址如下:http://example.com/username&emailaddress
现在你原来的规则:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z-]+)/?$ /index.php?u=$1 [L,QSA]