Results 1 to 7 of 7

Thread: Regular expressions

  1. #1
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608

    Regular expressions

    Hi All,

    If i want to redirect like this:

    Code:
    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

  2. #2
    King of da Wackos Nintendo's Avatar
    Join Date
    Oct 2004
    Location
    Planet Zeekois
    Posts
    166
    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.

  3. #3
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608
    Hmm, it didn't seem to do anything with that added - before or after...

    I have it working like this:

    Code:
    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 :

    Code:
    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..

  4. #4
    Working. Masetek's Avatar
    Join Date
    Aug 2005
    Location
    Aust
    Posts
    543
    Don't you just lose mod_rewrite! lol

  5. #5
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608


    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

  6. #6
    King of da Wackos Nintendo's Avatar
    Join Date
    Oct 2004
    Location
    Planet Zeekois
    Posts
    166
    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.

  7. #7
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608
    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •