#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2

    Simple .htaccess RewriteBase Ignored?


    Hi.

    I'm trying to use .htaccess to have clean url's. But it's ignoring my rewriteBase and always looking in the root of my website

    the files are in http://mysite.be/rally/

    Code:
    RewriteEngine On
    RewriteBase /rally/
    RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1
    RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1
    But it's not finding my css files, it keeps looking at http://mysite.be/..... not in the rally folder

    Anything I'm doing wrong? thanks!
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    Your rules don't match any files that have a "." in the filename. Browsers can't tell that a rewrite has taken place and so will look for files where they appear to be.

    I recommend not using RewriteBase unless you really need it.

    So all of the files for the site are in the rally directory and not in the web-root? If so, try this:
    Code:
    RewriteEngine On
    RewriteRule ^\/?([a-zA-Z0-9]+)\/?$ rally/index.php?page=$1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^\/?([a-zA-Z0-9]+\.(css|js|jpg|png|svg|gif))$ rally/$1
    Last edited by Kravvitz; August 1st, 2013 at 09:56 PM.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    Originally Posted by Kravvitz
    Your rules don't match any files that have a "." in the filename. Browsers can't tell that a rewrite has taken place and so will look for files where they appear to be.

    I recommend not using RewriteBase unless you really need it.

    So all of the files for the site are in the rally directory and not in the web-root? If so, try this:
    Code:
    RewriteEngine On
    RewriteRule ^\/?([a-zA-Z0-9]+)\/?$ rally/index.php?page=$1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^\/?([a-zA-Z0-9]+\.(css|js|jpg|png|svg|gif))$ rally/$1
    Thanks for the reply. Problem is I have a test- and production server, I thought the rewriteBase was used to easily switch between the two? Now i would have to rewrite the .htaccess if i switch environment ? thanks!
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    You're welcome.

    I use different .htaccess files for different servers when needed myself.

    Code:
    I thought the rewriteBase was used to easily switch between the two?
    *shrugs* I haven't heard that. You can read what the documentation says if you want.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo