Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

We used to have a URL

http://www.abc.com/index.php?itemID=144

which is moved to

http://www.abc.com/index.php?itemID=1556

we want our users which are hitting the above url(144) to reach to 1556. How can it be achieved. If with mod_rewrite or anything else.

share|improve this question

migrated from stackoverflow.com Jun 30 '11 at 20:10

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer 1

up vote 6 down vote accepted

Not sure if you want to redirect only 144=>1556 or it is just an example. Anyway you can try this:

Options +FollowSymlinks -MultiViews
RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)id=144(&|$) [NC]
RewriteRule ^(index\.php)/?$ /$1?id=1556 [NC,R,L]

Explanation:

  • RewriteCond is making sure there is id=144 in query string
  • RewriteRule is making sure that request URI is index.php (optionally followed by a trailing slash).
  • If both conditions are satisfied then rule will redirect to /index.php?id=1556. (Note use of back reference $1 instead of repeating index.php here).
  • Flags used are:

    1. NC - ignore case comparison
    2. R - redirect (by default with status = 302)
    3. L - Mark it as last rule

If you really want to replace multiple old IDs to new IDs then I will suggest you to take a look at: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritemap

share|improve this answer
    
i just want to redirect url with itemid 144 to 1556 –  sushil bharwani Jun 30 '11 at 4:54
    
can u please explain a little more on what you have written in RewriteCond and RewriteRule –  sushil bharwani Jun 30 '11 at 4:54
    
what is [NC,R,L,QSA] –  sushil bharwani Jun 30 '11 at 5:01
    
@sushil: added some explanation but I would humbly suggest: httpd.apache.org/docs/current/mod/mod_rewrite.html for better documentation on mod_rewrite. –  anubhava Jun 30 '11 at 5:09
    
Its recognizing the ItemId=144 but doesnot redirect to the new one correctly taking me to abc.com/xampp/spash.php –  sushil bharwani Jun 30 '11 at 5:17
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.