1. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2006
    Kent, England
    Rep Power

    Mod_rewrite expression to NOT match a whole word

    This is probably really easy, but it is driving me nuts.

    I have a .htaccess as shown below that works. It will send anything with /admin to the secure port. And then it will correctly rewrite the urls.

    What I need to do is send anything on HTTPS that is NOT for /admin to the HTTP port.

    RewriteEngine on
    Options +FollowSymLinks
    RewriteBase /
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule ^admin/?$ https://%{HTTP_HOST}/admin [L,N]
    RewriteCond %{SERVER_PORT} ^443$
    RewriteRule ^(?!admin)/?$ http://%{HTTP_POST}/$1 [L,N]
    ###  HERE I want to send any HTTPS request NOT to /admin/ to HTTP the above doesn't work..
    RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
    How do I say not "admin" - I seem to be able to do not a or not d and so on!
    Last edited by ElijaTheGold; November 9th, 2008 at 06:33 AM.
    It turns out there are stupid questions. And I don't know the answers!
    Over 50? Visit the Saga Zone - Social Networking for the Over 50's

    For every action there is an equal and opposite - government program
  2. #2
  3. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Rep Power
    I know nothing about Apaches Rewrite_Mod, but the regex:

    will only match an empty string or the string "/". That is because look arounds do not match anything: they're zero width.

    So, to match any url that does not start with the string "admin/" at the root, you'll have to do something like this:

    or possibly


IMN logo majestic logo threadwatch logo seochat tools logo