0

对不起我的英语。我制作了一个品牌目录网站。在访问品牌页面之前,我使用这样的请求:

mydomain.com/fiche.php?id=115

其中 id 是我的目录中品牌的 id

我更改了品牌页面的结构,现在使用此请求:

mydomain.com/annuaire.php?type=fiche&id_marq=115

id变成了哪里id_marq

我尝试使用这样的重写规则:

RewriteRule ^fiche.php$ http://www.annuaire-sites-officiels.com/annuaire.php?detail=fiche&id_marq=$1 [L,QSA,R=301] 

将旧链接重定向到新页面,但结果不传递 id_marq 值,并且 url 是:

http://www.annuaire-sites-officiels.com/annuaire.php?detail=fiche&id_marq=&id=115

&id=也是。

我究竟做错了什么?

4

2 回答 2

0

Your rule is not evaluating query string and that's why its not capturing id query parameter.

Change your code to:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^id=([^&]+) [NC]
RewriteRule ^fiche\.php$ /annuaire.php?detail=fiche&id_marq=%1 [R=302,L,QSA,NC]

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

于 2013-05-28T16:43:37.973 回答
0

查看正则表达式反向引用可用性:

Apache Back 引用

您必须捕获查询字符串。[QSA]将它原封不动地传递出去,所以除非你使用id任何你不需要那段代码的东西。您的301 重定向是正确的,因为这是永久重定向。请记住,如果您添加了失败的重定向,您的浏览器可能会缓存该重定向,因此它可能看起来无法正常工作。

在这个字符串匹配中,我只捕获数字以防止有人通过星号*和 XSS 之类的东西来利用您的网站。

我没有[NC]在我的代码中包含和匹配,因为当您允许多个案例时,它们看起来像是搜索引擎的不同 URL(对 SEO 不利)。

RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^fiche.php$ http://%{HTTP_HOST}/annuaire.php?detail=fiche&id_marq=%1 [R=301,L]
于 2013-05-28T16:43:16.673 回答