Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: [htaccess] RewriteBase relative to folder |
|
Author |
|
marmz
Joined: 24 Aug 2016 Posts: 3 Location: Italy, Pescara
|
Posted: Wed 24 Aug '16 18:22 Post subject: [htaccess] RewriteBase relative to folder |
|
|
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:
www.mysite.com (docroot: /var/www/html/mysite)
or
localhost/mysite (docroot: /var/www/html)
if i set RewriteBase /
it works for www.mysite.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 change RewriteBase "dynamically" and make the rules work for any possible "request"? |
|
Back to top |
|
marmz
Joined: 24 Aug 2016 Posts: 3 Location: Italy, Pescara
|
Posted: Thu 01 Sep '16 15:26 Post subject: SOLUTION |
|
|
For anyone who had the same problem, this is ONE possible solution:
Code: | # 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 |
|
Back to top |
|
|
|
|
|
|