使用.htaccess中的mod_rewrite在请求开头获取问号

时间:2011-10-30 14:39:29

标签: .htaccess mod-rewrite

情景:

当用户输入myhomepage.com/username时,他/她应该被重定向到myhomepage.com/?username

分别为:myhomepage.com/index.html?username

如果用户输入带有问号的网址:myhomepage.com/?username,则应忽略mod_rewrite

修改

这是我试过的:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html?$1

1 个答案:

答案 0 :(得分:1)

RewriteCond

中搜索空的查询字符串
RewriteEngine On
# Rule only applies when we have an empty querystring
RewriteCond %{REQUEST_QUERYSTRING} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html?$1