PDA

View Full Version : Regular expressions



r2d2
03-23-2006, 02:55 PM
Hi All,

If i want to redirect like this:



RedirectMatch permanent ^/([^.]+).html$ http://www.same_domain.com/$1/


ie /anything.html to /anything/

Is there anyway I can stop that rule working for /index.html?

I think Apache is redirecting www.domain.com to www.domain.com/index.html, then the rule changes it to www.domain.com/index/ which I don't really want.

Cheers,

Chris

Nintendo
03-23-2006, 03:34 PM
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^index/$ http://www.domain.com/index.html [R=301,L]

after that code, will either change the URL back to index.html and stay there, or it might go bonkers with the infinite loop.

r2d2
03-23-2006, 04:52 PM
Hmm, it didn't seem to do anything with that added - before or after...

I have it working like this:



RedirectMatch permanent ^/([^.]+).html$ http://www.domain.co.uk/$1/
RedirectMatch permanent ^/index/$ http://www.domain.co.uk/index.php


Which would be ok I guess..



Hmm, now I have it working with :



RedirectMatch permanent ^/([^x]+).html$ http://www.crispen.co.uk/$1/


which I believe is just matching anything without an 'x' - do you know how I can match anything that isnt 'index'. I tried [^(index)]+ and [^i^n^d^e^x]+ but they just do things without those letters, nothing to do with them in that order..

Masetek
03-23-2006, 06:22 PM
Don't you just lose mod_rewrite! lol

r2d2
03-24-2006, 12:49 AM
:)

Having been puzzling on that for about 3 days, I have decided that mod_rewrite is the work of satan - just invented to drive everyone crazy :)

Nintendo
03-24-2006, 02:17 AM
Try using RewriteRule for doing the original redirect. Then redirecting the index/ back to index.html.

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^([^x]+).html$ http://www.crispen.co.uk/$1/ [R=301,L]
RewriteRule ^index/$ http://www.crispen.co.uk/index.html [R=301,L]

If that doesn't do it, I don't know what will.

r2d2
03-24-2006, 06:28 AM
Hmm, I think that configuration didn't work because of the extra bit that WordPress uses (RewriteRule . /index.php [L]) - I think you end up with infinite loop or no redirect...

Anyway, I have a couple of options that work now using 'RedirectMatch', so I think I'll go with that - I'm not sure my mental health could take doing any more of the with mod_rewrite! Thanks for you suggestions though Nintendo! :)