htaccess问号重定向多个不同的静态URL

时间:2013-07-05 06:41:46

标签: .htaccess

我不想重定向以下网址:

1。 来自:http://www.example.com/tr/component/content/article?id=11 TO:http://www.example.com/services/terms/

2。 来自:http://www.example.com/tr/component/content/article?id=45 TO:http://www.example.com/services/cars/

我有以下代码:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{QUERY_STRING} id=11
RewriteRule (.*) http://www.example.com/services/terms/? [R=301,L]

RewriteCond %{QUERY_STRING} id=45
RewriteRule (.*) http://www.example.com/services/cars/? [R=301,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]
</IfModule>

但是使用上面的代码我可以写下以下内容 - 最后到“条款”页面:

http://example.com?id=11

哪个错了。我应该改变什么?

1 个答案:

答案 0 :(得分:1)

确保没有其他重定向源。

我只是将你的.htaccess粘贴到我的Apache中,一切都像你想要的那样。

修改:根据您的评论,您只需将(.*)规则替换为您希望重定向工作的网址:

RewriteCond %{QUERY_STRING} id=11
RewriteRule /?tr/component/content/article(.*) http://www.example.com/services/terms/? [R=301,L]

RewriteCond %{QUERY_STRING} id=45
RewriteRule /?tr/component/content/article(.*) http://www.example.com/services/cars/? [R=301,L]