2013-05-31 51 views
0

看来rewritemap不考虑匹配网址中的查询参数。请提出解决方案。RewriteMap不适用于带查询参数的网址

我在httpd.conf文件设置:

RewriteMap redirects dbm=db:/usr/local/apache/conf/redirects.db 
RewriteCond ${redirects:$1} !="" 
RewriteRule ^(.*)$ ${redirects:$1} [redirect=permanent,last] 

重定向文件中有网址,理了理

/same_url/ http://mysite.com/ 
/same_url/?q=1 http://mysite.com/q2=1 
/same_url/?q=2 http://mysite.com/q2=2 
/same_url/?q=3 http://mysite.com/q2=3 

但所有4个网址越来越仅针对http://mysite.com。所以它似乎只匹配非查询部分。

请帮忙。

+0

它看起来像apache不考虑'重写规则'中的查询参数。 – Shatiz

+0

与RewriteRule匹配时查询字符串被删除。你应该看看'%{QUERY_STRING}'。 – Gerben

回答

3

看着你的RewriteMap,看起来你不需要使用地图。 你可以不用地图:

RewriteCond %{QUERY_STRING} ^q\=([0-9]+)$ 
RewriteRule ^/same_url/(.*)$ http://example.com/q2=%1 [redirect=permanent,last] 

,请注意%1在重写规则逆向引用到了比赛中的RewriteCond。

如果你仍然想使用你可能有一个重写地图“改造”的查询字符串弄成路径 的规则可能是:

RewriteCond %{QUERY_STRING} ^q\=([0-9]+)$ 
RewriteRule ^/(.*)$ /$1/q=%1 <-- here the GET param is transformed to something in the path 

RewriteMap redirects dbm=db:/usr/local/apache/conf/redirects.db 
RewriteCond ${redirects:$1} !="" 
RewriteRule ^(.*)$ ${redirects:$1} [redirect=permanent,last] 

你必须改变你的地图不考虑GET参数:

/same_url/ http://example.com/ 
/same_url/q=1 http://example.com/q2=1 
/same_url/q=2 http://example.com/q2=2 
/same_url/q=3 http://example.com/q2=3