Tuesday, January 24, 2012

.htaccess Rewrite Rule for converting /names.php?name=boy&id=23&page=1 to names/boy/23/1

Pass the Query string through url not by traditional method but by using mod rule in .htaccess file
 /names.php?name=boy&id=23&page=1 to names/boy/23/1


RewriteEngine on
RewriteCond %{QUERY_STRING} ^name=(.+)&id=(.+)&page=(.+)$ [NC]
RewriteRule ^names\.php$  /names/%1/%2/%3? [R=301,NE,NC,L]

If you want to convert all the pages to
http://localhost/ram1/2/3
http://localhost/ram1.php?id=2&page=3
http://localhost/ram1/1
http://localhost/ram1.phppage=1
 use the rewrite rule below to automatically converts to corresponding Query String


RewriteEngine on
RewriteRule ^(.+)/([0-9]+)/([0-9]+)/?$ $1.php?id=$2&page=$3 [L]
RewriteRule ^(.+)/([0-9]+)/?$ $1.php?page=$2 [L]



3 comments:

  1. Hi!
    Could you help me?

    I have a store in magento which is http://mydomain.com/store.

    What I want Is to redirect/rewrite that URL to http://mydomain.com/store/highlights.

    I have to do it through htaccces, because I have a custom version of magento which doesnt allow setting cmd home page for the stores.

    Could you help me ? I would apreciate it very much.

    Thanks

    ReplyDelete
  2. After a long research i got a way to redirect using .htaccess
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/store/$
    RewriteRule ^(.*)$ http://localhost/store/highlights [R,L]
    put this .htaccess rule inside store folder

    ReplyDelete
  3. hi ,

    our website url is like this http://mydomain.com/default/storename and i want to change it to http://mydomain.com/storename using htaccess rewrite rule i tried with many regular expression but it is not working.
    Could you help me ?

    ReplyDelete