2011-07-11 204 views
0

我已经做了一些URL掩码,它的一切都很好。我有我想现在要解决的一个问题:htaccess url masking mod重写

RewriteRule ^(.*)/(.*)/clubs/(.*)/$ teams.php?competition=$1&season=$2&teamid=$3 

与上面我可以访问同一页面2种方式,www.domain.com/premier-league/2010-2011/arsenal/www.domain.com?competition=premier-league&season=2010-2011&teamid=arsenal

有没有在我的重写规则的方式我可以重定向URL(理想的301)是有人通过不整洁的方式“www.domain.com?competition=premier-league&season=2010-2011&teamid=arsenal”?

在此先感谢

+0

我喜欢阿森纳.. –

回答

0

如果添加这个符合你的“逆”模式层出不穷重写规则,并标记都为[L] AST规则,可能的工作。我首先重写URL来包含查询字符串,[C] hain那一个到下一个规则。之后,我们[R]转发浏览器。

RewriteRule ^(.)/(.)/clubs/(.*)/$ teams.php?competition=$1&season=$2&teamid=$3 [L] 
RewriteRule ^(.+) $1%{QUERY_STRING} [C] 
RewriteRule ^teams.php?competition=([a-zA-Z0-9]+)&season=([a-zA-Z0-9]+)&teamid=([a-zA-Z0-9]+)$ $1/$2/clubs/$3/ [R=301,L] 

注意我还没有测试过这个或第二条规则的正则表达式。可能需要稍微调整字符范围。此外,我还没有测试第二条规则中的查询字符串重写。

编辑:在这里看到的mod_rewrite一些常见的用例:http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

+0

很抱歉,但'RewriteRule'不与查询字符串以这种方式工作。 – LazyOne

+0

有没有一种方法可以将我的旧网站的所有页面重定向到我的新域主页? –

+0

啊,显然!您需要使用重写链来附加它。让我检查一下是否有效... –