htaccess的重定向不工作与参数的URL [英] htaccess redirect not working with URLs with parameters

查看:219
本文介绍了htaccess的重定向不工作与参数的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重定向的index.php行动=这与放大器;?ID = 1到index.php行动=这与放大器;?ID = 2

I want to redirect index.php?action=this&id=1 to index.php?action=this&id=2

我试过code低于我的.htaccess,但它并没有帮助

I tried the code below in my .htaccess but it didn't help

redirect 301 index.php?action=this&id=1 http://mysite.com/index.php?action=this&id=2

我究竟做错了什么?这可能是一个解决办法?

What am i doing wrong here? what could be a workaround?

推荐答案

为了您有无可以使用的mod_rewrite ,以匹配特定的查询字符串。请检查是否已安装/让您的主机上。在这种情况下,规则将是这样的:

In order to match specific query string you have to use mod_rewrite. Please check if it is installed/allowed on your host. The rule in this case will be something like this:

# most likely be required for rewrite rules to function properly
Options +FollowSymLinks +SymLinksIfOwnerMatch

# Activate Rewrite Engine
RewriteEngine On
RewriteBase /

# actual rule
RewriteCond %{QUERY_STRING} ^action=this&id=1 [NC]
RewriteRule ^index\.php$ /index.php?action=this&id=2 [R=301,L]

这需要放置在.htaccess在网站根目录。如果放在其他地方一些小的变化可能是必需的。

This needs to be placed in .htaccess in website root folder. If placed anywhere else some small changes may be required.

这条规则将仅重定向 /index.php?action=this&id=1 /index.php?action=this&id = 2 并没有其他网址(就像你在你的问题问)。

This rule will only redirect /index.php?action=this&id=1 to /index.php?action=this&id=2 and no other URLs (just as you asked in your question).

这篇关于htaccess的重定向不工作与参数的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆