1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[htaccess] RewriteBase relative to folder

Discussion in 'Apache' started by marmz, Aug 25, 2016.

  1. #1
    Hi. I'm new to this forum, this is my first post.
    This is my "scenario":

    I have a site on: /var/www/html/mysite

    this site is reachable by:
    mysite.mydomain.com (docroot: /var/www/html/mysite)
    or
    localhost/mysite (docroot: /var/www/html)

    if i set RewriteBase /
    it works for mysite.mydomain.com

    if i set RewriteBase /mysite/
    it works for localhost/mysite

    Is there way to set RewriteBase automatically to the directory .htaccess is in?
    Or some other way to make the rules work for any possible "request"?
     
    marmz, Aug 25, 2016 IP
  2. marmz

    marmz Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    For anyone who had the same problem, this is ONE possible solution:

    # BASE
    RewriteBase /

    # Store the current location in an environment variable CWD
    RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
    RewriteRule ^.*$ - [E=CWD:%2]

    # Just by prefixing the environment variable, we can safely rewrite anything now
    RewriteCond %{REQUEST_FILENAME} !-f
    ^(.*)$ %{ENV:CWD}index.php?var=$1 [L]

    Hope this could be helpful.. ;)
     
    marmz, Sep 1, 2016 IP