我有这段代码将www.domain.com重定向到pagina /公共文件:
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ pagina/public/$1 [L,NC]
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
我想要一个新规则,如果URL具有www.domain.com/panel,则重定向到panel / public
我在服务器中有两个文件夹:pagina /和panel /,每个都有公用文件夹。
我尝试过:
RewriteCond %{THE_REQUEST} /panel/([^\s?]*) [NC]
RewriteRule ^panel/ %1 [L,NE,R=302]
RewriteRule ^((?!panel/).*)$ panel/$1 [L,NC]
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
但是它不起作用,我该怎么办?
谢谢
更新#1
我更改了htaccess:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(panel) - [L]
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ pagina/public/$1 [L,NC]
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
所以我让它进入panel /文件夹内,但是如果我在panel /子文件夹中使用Slim的常规htaccess则无法正常工作。有想法吗?
更新#2
现在问题出在Slim中,所以我将其添加到依赖项中,并且它是可行的:)
$container['environment'] = function () {
$scriptName = $_SERVER['SCRIPT_NAME'];
$_SERVER['REAL_SCRIPT_NAME'] = $scriptName;
$_SERVER['SCRIPT_NAME'] = dirname(dirname($scriptName)) . '/' . basename($scriptName);
return new Slim\Http\Environment($_SERVER);
};