Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch Question

         

paull2k

11:23 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



Ok. I will try this again, since I didn't get the responses I had hoped for before. What I want to do is redirect:
[example.com...] to
[example.com...]

Using RedirectMatch.

jetboy

11:42 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



I'm notoriously poor at regex, but does this work?

RedirectMatch /pages/(.*)/index\.php [example\.com...]

paull2k

11:48 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



Yes, it works, but only when I use it like this:
RedirectMatch /pages/(.*)/index\.php [example.com...]

I also want it to work if index.php is not specified, like this:
[example.com...]

jetboy

12:09 am on Mar 24, 2005 (gmt 0)

10+ Year Member



Oops.

RedirectMatch /pages/(.*)/index\.php [example.com...]
RedirectMatch /pages/(.*)/$ [example.com...]

In theory anyway.

At the moment xx can be anything. If you know you're only going to have numerals in there for example you can change (.*) to be ([0-9]*)

sitz

2:13 am on Mar 24, 2005 (gmt 0)

10+ Year Member



Another version would look like this:

RedirectMatch /pages/([^/]+)(/?¦index\.php)?$ http://www.example.com/?page=$1

Interestingly, under apache 1.3 anyway (untested under 2.0), the redirect actually goes to:

http://www.example.com/%3fpage=xx

Yay escaping. =)

If that became an issue, you could just use mod_rewrite (assuming such an option is available):


RewriteEngine on
RewriteRule ^/pages/([^/]+)(/?¦index\.php)?$ http://www.example.com/?page=$1 [L,R]

I /think/ that regex covers all the bases, although I'm a bit fried right now. =)

Oh, an jetboy's right (well, almost); if the page is always going to be numeric, something like this:

RedirectMatch /pages/([0-9]+)(/?¦index\.php)?$ [example.com...]

You want [0-9]+ and not [0-9]*, because [0-9]* would match on an empty string (the '*' matches "zero or more occurrences of the preceding atom").

jetboy

7:47 am on Mar 24, 2005 (gmt 0)

10+ Year Member



Thanks sitz, I was digging a big hole for myself there ... ;)