Web Hosting Talk







View Full Version : Any thoughts on my mod_rewrite?


Philco
03-25-2005, 10:30 AM
I came up with this mod_rewrite to solve a problem.

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^customsites/(.*)/index.php /test/index.php?userid=$1 [L,QSA]

My usage:
I`m going to use it to direct users who come to my site with a URL like:
mysite.com/customsites/2/index.php?type=43cmd=6

What it does is to use mod_rewrite to examine the URL extract the /2/ when someone comes in with customsites/ so that the 2 can be appended to the URL as userid=2 and the whole thing plus any other variables redirected to the /test/index.php script for showing a page customised for that userid via php and mysql.

My explanation:
The RewriteCond grabs everything passed in on the QUERY_STRING

The RewriteRule looks for a URL with customsites in it, then assigns the value in the next part to $1 and also accepts the URL if the filename part is index.php.

The QSA appends everything found in the RewriteCond to the new path and sends it all on together.

It works fine, but I cobbled it together with my limited mod_rewrite experience and I`m asking if anyone who knows about mod_rewrite can see any problems with it.

Cheers

Philco

hiryuu
03-25-2005, 03:40 PM
QSA doesn't mention anything about using RewriteCond values. Are you sure that RewriteCond is needed at all?

Philco
03-26-2005, 07:40 AM
Thanks hiryuu

you are right it does not need the RewriteCond %{QUERY_STRING} (.*)

The QSA-Flag will append the exsisting queryString on its own.

so now I have:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^customsites/(.*)/index.php /test/index.php?userid=$1 [L,QSA]

cheers..