Mod Rewrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leewad
Forum Commoner
Posts: 91
Joined: Tue May 11, 2004 8:32 am

Mod Rewrite

Post by leewad »

Hi

Heres an easy one but just cant get my head around it

I need to rewrite the following Url:

http://domain1.com/images.php?Id=25

to

http://domain2.com/images.php?Id=25

Id not always 25 !!

Any Ideas ??
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

RewriteEngine on
RewriteRule ^/images.php?Id=(d+) http://domain2.com/images.php?Id=$1
leewad
Forum Commoner
Posts: 91
Joined: Tue May 11, 2004 8:32 am

Post by leewad »

Thanks but that didn`t work - what is the (d+) for ?
should it not be something like

Code: Select all

RewriteRule  ^/images.php?Id=(.*)$  http://domain2/image.php?Id=$1
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

leewad wrote:Thanks but that didn`t work - what is the (d+) for ?
I was under impression that mod_rewrite used PCRE regexps. It didn't.
leewad wrote: should it not be something like

Code: Select all

RewriteRule  ^/images.php?Id=(.*)$  http://domain2/image.php?Id=$1
Nope, it should be something like:

Code: Select all

RewriteRule  ^/images.php?Id=(ї0-9]+)$  http://domain2/image.php?Id=$1
leewad
Forum Commoner
Posts: 91
Joined: Tue May 11, 2004 8:32 am

Post by leewad »

Nope not that either !

Any more suggestions ?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

$_SERVER['QUERY_STRING'] and tell us what that returned.
leewad
Forum Commoner
Posts: 91
Joined: Tue May 11, 2004 8:32 am

Post by leewad »

Nothing - what should it have returned ?

I have the another mod_rewrite which works fine:

Code: Select all

^newimage/(.*).jpg$ http://www.domain2/sales/$1.jpg
But cant get the other one to work
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Not tested but you could try....

Code: Select all

RewriteEngine on 
RewriteRule  ^images\.php\?Id=(ї0-9]+)$  http://domain2/image.php?Id=$1 їR]
or, as escaping special characters is borked on some versions.....

Code: Select all

RewriteEngine on 
RewriteRule  ^images\.php(.*)  http://domain2/image.php$1 їR]
Post Reply