在计算RewriteCond指令时,apacherequest_URI会在父路径前面加上前缀

在计算RewriteCond指令时,apacherequest_URI会在父路径前面加上前缀,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我有一个在Apache 2.4上运行的站点,它有两个.htaccess文件,如下所示: /.htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] </IfModule> <IfModule mod_rewrite.c> RewriteEngine On

我有一个在Apache 2.4上运行的站点,它有两个.htaccess文件,如下所示:

/.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ public/    [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
    RewriteEngine On

    ## Redirect PDF files to application (bootstrap starts at index.php) for authentication
    RewriteCond %{REQUEST_URI} ^/(protected/path/.*\.pdf)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

但是,我正在寻找一种解决方案,它允许我保留这两个文件,并简单地“修复”
%{REQUEST\u URI}
变量值,使其不包括父“public”路径。我觉得我在某个地方缺少了一个简单的标志或
RewriteBase
或类似的指令。任何想法都将不胜感激。

您使用的动态配置文件越多,您的http服务器就会越慢。实际上最好的做法是根本不使用这些文件,而是将这些规则放在http服务器(虚拟)主机配置中。Myb将/public/.htaccess更改为
RewriteRule^/public/(protected/path/*\.pdf)$index.php?p=$1[NC,QSA,L]
?如果这就是你的目标?
<IfModule mod_rewrite.c>
    RewriteEngine On

    ## Redirect PDF files to application (bootstrap starts at index.php) for authentication
    RewriteCond %{REQUEST_URI} ^/(protected/path/.*\.pdf)$ [NC]
    RewriteRule (.+) public/index.php?p=$1 [QSA,L]

    RewriteRule ^$ public/    [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>