We used to have a URL


which is moved to


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.


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]


  • 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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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