3

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

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?

2
  • As per documentation URL should start with leading slash (as already mentioned by Shaikh). Unfortunately Redirect directive does not work with query string parameters -- only with path part (in your case it will be index.php). Your only hope -- is to use mod_rewrite. Please check if it is present/enabled on your server - if yes, then I may help you here. Commented Apr 19, 2012 at 18:07
  • See my answer -- sorry for a delay -- did when I had a chance. Commented Apr 22, 2012 at 23:58

3 Answers 3

2

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]

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

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).

Sign up to request clarification or add additional context in comments.

Comments

2

You could try just adding this on the page that you want redirected

<meta HTTP-EQUIV="REFRESH" content="0; url=index?action=this&id=2">

1 Comment

no i don't want meta refresh. it's kinda not possible here in my situation.
1

just add the forward slash before the first url like

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.