Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mod rewrite与oth服务器和userdir一起使用_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php mod rewrite与oth服务器和userdir一起使用

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_

我正在使用apachemod_rewrite和userdir。 我想写一个在任何地方都可以使用的.htaccess,有没有办法删除RewriteBase或使用Apache变量设置它

这是我的.htaccess:

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问题