logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: mod_rewrite query string to query string
Author
mystic-dragon



Joined: 17 Aug 2007
Posts: 1

PostPosted: Fri 17 Aug '07 16:19    Post subject: mod_rewrite query string to query string Reply with quote

Hey

I'm trying to rewrite an url to my website with mod_rewrite.
I have something like this:
Code:
http://www.example.com/home.php?link=mypage&product=235

Due to a new website I have new urls but I want the old once to stay compatible.

I tried to rewrite them to:
Code:
http://www.example.com/index.php?product=235


I have tried the following rewrite rule:
Code:
 
RewriteEngine On
RewriteRule home.php\?link=mypage&product=(.*) index.php?product=$1


But it doesnt seem to work, adding ^ and $ doesn't help aswell.
Could any one help me out here?

Thanks in advance.
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Fri 17 Aug '07 18:01    Post subject: pls ask mod_rewrite questions at http://forum.modrewrite.com Reply with quote

In general, please ask mod_rewrite questions at http://forum.modrewrite.com/ rather than here.

Since your's is a simple case, here's the answer:

RewriteRule won't match the query string part - just the filename part: home.php. See the mod_rewrite docs.

The dot in home.php needs a backslash, else it will match any character. For example homeXphp would match your regex.

I think you want this:
Code:
RewriteEngine On
RewriteCond  %{QUERY_STRING}  link=mypage&product=(.*)
RewriteRule  ^home\.php$  index.php?product=%1

Note that when you take the substitution from RewriteCond instead of from RewriteRule you use %1 instead of $1.

-tom-
Back to top


Reply to topic   Topic: mod_rewrite query string to query string View previous topic :: View next topic
Post new topic   Forum Index -> Apache