需要.htaccess文件强制URL为/ abc而不是?a = abc

时间:2016-06-04 16:29:59

标签: php apache .htaccess redirect mod-rewrite

我有一个脚本(.php& smarty combined),它显示的页面类似于?a = abc,而我希望它将所请求的页面显示为/ abc。下面我的代码与我想要的完全一样,但问题是每当我访问/?a = abc时,它会显示页面,但不会将URL转换为地址栏中的/ abc 。那么你们可以帮忙吗?

以下是我在我网站的.htaccess文件中使用的代码:

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?a=$1 [L]

提前致谢。

1 个答案:

答案 0 :(得分:1)

将您的重写条件发布到:

RewriteCond %{THE_REQUEST} (?:/|/index\.php)\?a=([^\s&]+) [NC]

现在它将匹配 /?a = foo /index.php?a=foo