0

我对 Apache 重写不太了解,我有一组我想做的要求:

1. http://domain.com/keyword ==> http://domain.com/index.php?c=keyword
2. http://domain.com/keyword?utm_source=affiliate ==> http://domain.com/index.php?c=keyword&utm_source=afiliate
3. Do not rewrite any request like http://domain.com/css/ http://domain.com/images/ 

我尝试学习并且已经能够编写这样的重定向来解决#1和#2:

RewriteEngine on
RewriteRule ^([A-Za-z0-9-+.,]+)\?*(.*)$ index.php?c=$1$2 [QSA]

这对我上面的要求中的#1 和#2 有效。但是,当我尝试访问这样的 URLhttp://domain.com/b时,会在 (PHP) 中产生以下结果$_SERVER['QUERY_STRING']: c=index.php&c=b

此外,如果我将标志更改为具有绝对域的 [R,QSA](只是因为我很好奇),我会得到一个连续循环重定向,这表明该规则正在被多次处理。

有人可以帮忙吗?

4

1 回答 1

1

尝试添加一对RewriteCond来过滤那些您不想被重写的路径,如下所示:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/css/
RewriteCond %{REQUEST_URI} !^/images/
RewriteRule ^([A-Za-z0-9-+.,]+)\?*(.*)$ index.php?c=$1$2 [QSA]
于 2012-10-18T19:20:39.837 回答