Forum Moderators: phranque

Message Too Old, No Replies

What is wrong with this .htaccess rule?

might be very easy to solve...

         

slyv

3:15 pm on Oct 25, 2007 (gmt 0)

10+ Year Member



Hello all!

I am trying this rule:
RewriteRule ^/explos/([0-9]+)/1/images/photo([0-9])([0-9])\.jpg http://www.example.com/explos/$1/images/$2/photo$3.jpg

My goal is to redirect from here:
http://www.example.com/explos/XX/1/images/photoYY.jpg
(XX= 1 or 2 digits, YY = 2 digits)

to here:
http://www.example.com/explos/XX/images/photoYY.jpg

Can somebody tell me what is wrong this this rule?

(example if you try http://www.example.com/explos/11/1/images/photo01.jpg you get a not found error, althrough http://www.example.com/explos/11/images/photo01.jpg exists...)

Thanks!

Slyv

[edited by: slyv at 4:05 pm (utc) on Oct. 25, 2007]

Philosopher

3:27 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, you'll want to edit your post and remove the specifics. TOS doesn't allow listing of specific URLs.

Now...on to your question...

Your rewrite rule shows

http://www.example.com/explos/$1/images/$2/photo$3.jpg

but you are wanting to redirect to

http://www.example.com/explos/XX/images/photoYY.jpg

Look at your $2 backreference...looks like the rewrite rule should be

http://www.example.com/explos/$1/images/photo$2$3.jpg

However, it would be better to simply lump the 2nd and 3rd backreferences together instead of doing them separately.

By the way...Welcome to WebmasterWorld!

[edited by: Philosopher at 3:29 pm (utc) on Oct. 25, 2007]

phranque

5:44 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, slyv!

slyv

6:30 pm on Oct 25, 2007 (gmt 0)

10+ Year Member



Thanks for the warm welcome, Philosopher & Phranque. I edited the message to remove the specifics (btw I learned one English expression, 'specifics' :-) )

I removed the obvious error reported by Philosopher, but still I get a 404.
My rule is now:
RewriteRule ^/explos/([0-9]+)/1/images/photo([0-9]+)\.jpg http://www.example.com/explos/$1/images/photo$2.jpg

I also tried: RewriteRule ^/explos/(.+)/1/images/photo(.+)\.jpg [forbidden-places.net...]
because my single digit numbers start with a 0 (01, 02, 03...)

404 too!

Thanks for your help!

Greetings, Slyv

Philosopher

6:37 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What about

RewriteRule ^explos/([0-9]+)/1/images/photo([0-9]+)\.jpg explos/$1/images/photo$2.jpg

I removed the initial slash. I'm also assuming you are wanting to do an internal rewrite not an external redirect which is why I also removed the "http://www.example.com/" from the target URL.

Unless I'm just missing something silly or your server is setup odd, that should work.

slyv

9:21 pm on Oct 25, 2007 (gmt 0)

10+ Year Member



Thanks Philo', you made it.
Now I just have to find out why my internal redirect using the full URL was not working!

Cheers!
Slyv

g1smd

12:57 pm on Oct 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What do you mean by "internal redirect"?

I use the terms "internal rewrite" and "external redirect" a lot. They are quite different.

slyv

5:18 pm on Oct 26, 2007 (gmt 0)

10+ Year Member



Sorry, I meant internal rewrite.
I add the domain name to my internal rewrite rule, and this did not work.

Slyv

g1smd

7:35 pm on Oct 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If it is an internal rewrite then you should really only specify the internal filepath where the content resides.