DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Linux Servers and Apache (http://www.daniweb.com/forums/forum33.html)
-   -   URL Rewriting pass query string (http://www.daniweb.com/forums/thread136460.html)

samarudge Jul 24th, 2008 6:44 am
URL Rewriting pass query string
 
Hi,
I have set up a URL rewriting rule for my website:
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)\.html$ /main.php?Area=$1&Page=$2
Which works fine if I request a page like
http://mysite.com/folder/something.html
it would show
http://mysite.com/main.php?Area=folder&Page=something
but I want to also be able to pass the rest of the query string so something like
http://mysite.com/folder/something.html?Bob=Jim
would pass the query string onto the main.php page like
http://mysite.com/main.php?Area=fold...ething&Bob=Jim
Is there a way to do this.
Regards,
Sam Rudge

tgbyhn Sep 7th, 2008 7:27 pm
Re: URL Rewriting pass query string
 
Hi Sam,

Quote:

Originally Posted by samarudge (Post 655068)
Hi,
I have set up a URL rewriting rule for my website:
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)\.html$ /main.php?Area=$1&Page=$2
Which works fine if I request a page like
http://mysite.com/folder/something.html
it would show
http://mysite.com/main.php?Area=folder&Page=something
but I want to also be able to pass the rest of the query string so something like
http://mysite.com/folder/something.html?Bob=Jim
would pass the query string onto the main.php page like
http://mysite.com/main.php?Area=fold...ething&Bob=Jim
Is there a way to do this.

Try this:
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)\.html$ /main.php?Area=$1&Page=$2 [PT,QSA]
Or this (the PT in the example above will make the viewer only see /some/url.html - and NOT /main.php?Area=x&Page=y - if you want the viewer to see/main.php etc remove the PT):
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)\.html$ /main.php?Area=$1&Page=$2 [QSA]
You can find more information here: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Adnan


All times are GMT -4. The time now is 6:57 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC