my.domain.com/3894 -> my.domain.com/index.php?id=3894

Discuss practical ways rearrange URLs using mod_rewrite.

my.domain.com/3894 -> my.domain.com/index.php?id=3894

Postby zachandsuch » Sun Feb 20, 2005 10:19 pm

How can I make
http://my.domain.com/3894
become
http://my.domain.com/index.php?id=3894

but for all numbers that follow the original /

thanks!
zachandsuch
 

Postby Caterham » Mon Feb 21, 2005 4:17 am

http://my.domain.com/3894
become
http://my.domain.com/index.php?id=3894
In this case you can use
Code: Select all
RewriteEngine On
RewritRule ^([0-9]+)/? index.php?id=$1 [L]


Bob
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby zachandsuch » Mon Feb 21, 2005 8:57 am

thanks!!!!!!!!!!!
zachandsuch
 

site.com/dir/file.gif => site.com/dir/index.php?src=file.

Postby Phydeaux » Mon Apr 25, 2005 8:26 am

I have a similar circumstance, but not limited to numbers as zackandsuch was.

Basically, I am using a php script to apply a watermark to images. So, if someone requests the raw image "//site.com/dir/file.gif", they will receive the processed image "//site.com/dir/index.php?src=file.gif"

Also, if someone requests "//site.com/dir/" with no specified file, it is okay to recieve "//site.com/dir/index.php?src=" because the script has error control for an empty parameter.

Thanks for your help!
Phydeaux
 

Re: site.com/dir/file.gif => site.com/dir/index.php?src=f

Postby Phydeaux » Mon Apr 25, 2005 11:52 am

Well, damn if that wasn't easy. :rolleyes:
Code: Select all
RewriteEngine On
RewriteRule (.*).gif$ index.php?src=$1.gif [L]


That code placed in the .htaccess of my "//site.com/dir/" will pass as a parameter anything ending in .gif.

Meanwhile, anything that does not end with .gif will return a 404.

And, "//site.com/dir/" by itself will (through other rules) redirect to index.php with no parameter.

I am a little concerned about the use of a total wildcard like (.*) but I can fine tune that later. Thank you for these forums.
Phydeaux
 

Postby Caterham » Thu Apr 28, 2005 4:04 am

RewriteRule ^(.*)\.gif$ index.php?src=$1.gif [L]
ou should use also a Anchor ^ to matk the start of the sting and escape the dot to mark it as literal tot (and not one single char)
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 40 guests

cron