Php mod rewrite与oth服务器和userdir一起使用
我正在使用apachemod_rewrite和userdir。 我想写一个在任何地方都可以使用的.htaccess,有没有办法删除RewriteBase或使用Apache变量设置它 这是我的.htaccess:Php mod rewrite与oth服务器和userdir一起使用,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我正在使用apachemod_rewrite和userdir。 我想写一个在任何地方都可以使用的.htaccess,有没有办法删除RewriteBase或使用Apache变量设置它 这是我的.htaccess: RewriteEngine On RewriteBase /~leo/lstronic/v2/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_
RewriteEngine On
RewriteBase /~leo/lstronic/v2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . ./index.php [QSA,L]
我还需要保留相对URL,我就是这样做的:
$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']);
有没有办法让最后两行在任何地方都能正常工作
Léo您可以使用此规则在env变量中动态生成
RewriteBase
,并在规则中使用它
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]
这解决了我遇到的Apache问题