leosw
leosw

Reputation: 105

mod-rewrite to work with oth server and userdir

I'm using Apache mod_rewrite and userdir. I want to write a .htaccess that works everywhere, is there a way to remove the RewriteBase or set it up using Apache variable ?

Here is my .htaccess :

RewriteEngine On

RewriteBase /~leo/lstronic/v2/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . ./index.php [QSA,L]

I also need to keep the relative URL, that's how I do this :

$config['root_directory']=__DIR__;
$config['project_subdirectory']=str_replace("/home/leo/public_html/","/~leo/",$config['root_directory']);
//$config['project_subdirectory']=str_replace($_SERVER['DOCUMENT_ROOT'],"",$config['root_directory']);

Is there a way to make the two last lines working everywhere ?

Léo

Upvotes: 1

Views: 67

Answers (1)

anubhava
anubhava

Reputation: 785196

You can use this rule to generate RewriteBase dynamically in an env variable and use it in your rules.

RewriteEngine On

RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . %{ENV:BASE}index.php [L]

Upvotes: 1

Related Questions