mod_rewrite situation - should be easy!

Discussion in 'Apache' started by LazyD, Jan 7, 2008.

  1. #1
    Currently I have my htaccess file setup like the following:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?page=$1 [L]

    This allows me to do http://mydomain.com/index and have that reference to index.php?page=index

    I want to be able to add an admin URL in there, I assumed I could change the htaccess file to look like the following:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^admin/(.*)$ admin.php?page=$1 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]

    However, when I go to http://mydomain.com/admin/index - I would assume that it would reference admin.php?page=index - That doesnt seem to be the case, instead it just goes to my index.php and screws up the relative links...

    Any suggestions on how to create the admin rule?
     
    LazyD, Jan 7, 2008 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    ([^.]+)

    RewriteRule ^([^.]+)$ index.php?page=$1 [L]
    RewriteRule ^admin/([^.]+)$ admin.php?page=$1 [L]
     
    Nintendo, Jan 8, 2008 IP
  3. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Should I just change my RewriteRules to that, or should I also remove the RewriteConds?
     
    LazyD, Jan 8, 2008 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    You can just repalce those two lines. I rarly ever use

    RewriteCond

    I always start with

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /

    with RewriteBase being the directory of .htaccess location.
     
    Nintendo, Jan 8, 2008 IP