Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch only for some files

htaccess redirectmatch

         

flapane

10:46 am on Mar 17, 2009 (gmt 0)

10+ Year Member



Hi!
l'd like to redirect pages of the kind map*.php from root to /maps/map*.php, I tried something like:
RedirectMatch 301 /map.*.php http://www.example.com/maps/$1

But the browser tells there is an addressing issue.
Furthermore, could excluding ONE particular mapfoo.php file be possible, so that it isn't redirected?
thanks

[edited by: coopster at 10:52 am (utc) on Mar. 17, 2009]
[edit reason] please use example.com, thanks! [/edit]

Caterham

12:01 pm on Mar 17, 2009 (gmt 0)

10+ Year Member



could excluding ONE particular mapfoo.php file be possible

That depends upon your apache version.

Modify your regEx to

^(map(?!foo\.)[^/.]+\.php)$

using a negative lookahead.

flapane

12:11 pm on Mar 17, 2009 (gmt 0)

10+ Year Member



Thanks.
What about the first part? Do you have any hints? I moved those pages, and I don't want to wait some days google to reindex the new locations, and some people already have those old addresses...

Caterham

12:13 pm on Mar 17, 2009 (gmt 0)

10+ Year Member



What about the first part?

That is already covered by the regular expression.

flapane

2:06 pm on Mar 17, 2009 (gmt 0)

10+ Year Member



I tought there was some piece missing, because I tried it
(RedirectMatch 301 ^(map(?!foo\.)[^/.]+\.php)$ http://www.example.com/maps/$1)

with mapfoo.php being excluded from the regex, and if I try to open, for example, http://www.example.com/mapeur.php I simply get a 404 and ain't redirected to www.example.com/maps/mapeur.php.

Caterham

2:36 pm on Mar 17, 2009 (gmt 0)

10+ Year Member



yes, the leading slash is missing

^/(map(?!foo\.)[^/.]+\.php)$

flapane

2:45 pm on Mar 17, 2009 (gmt 0)

10+ Year Member



That worked, sorry, I am not very skilled at perl regexp, thank you so much.