Apache 重写别名目录

Apache 重写别名目录,apache,mod-rewrite,mod-alias,Apache,Mod Rewrite,Mod Alias,我试图首先使用Alias文件夹将项目文件存储在与我的DocumentRoot不同的位置,然后在此请求上执行mod_rewrite。但是,它似乎没有解析.htaccess文件 这是我的别名文件的内容: Alias /test F:/Path/To/Project <Directory F:/Path/To/Project> Order allow,deny Allow from all </Directory> 当我删除别名时,一切正常 mod_别名始终

我试图首先使用Alias文件夹将项目文件存储在与我的
DocumentRoot
不同的位置,然后在此请求上执行
mod_rewrite
。但是,它似乎没有解析
.htaccess
文件

这是我的别名文件的内容:

Alias /test F:/Path/To/Project

<Directory F:/Path/To/Project>
    Order allow,deny
    Allow from all
</Directory>

当我删除别名时,一切正常

mod_别名始终优先于mod_重写。您永远不能用mod_rewrite重写mod_alias指令


在这种情况下,可能会对您有所帮助。

这里有一个解决方案,可以解决一些您尝试使用别名和重写,但由于它们冲突而无法使用的情况

假设特定应用程序的
DocumentRoot
/var/www/example.com/myapp
,并且具有以下基本目录结构,其中公共请求要么是针对
public
中的文件(例如css文件),要么通过
index.php
路由

myapp/
|- private_library/
   |- private_file.php
|- private_configs/
   |- private_file.php
|- public/
   |- index.php
   |- css/
      |- styles.css
目标是只提供
public\u webroot
内的内容,但是,URL应该是
example.com/myapp
而不是
example.com/myapp/public

以下内容似乎应该有效:

DocumentRoot /var/www/example.com
Alias /myapp /var/www/example.com/myapp/public
<Directory /var/www/example.com/myapp/public>
    # (or in this dir's .htaccess)
    RewriteEngine On
    RewriteBase /public
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [QSA,PT]
</Directory>

就这些

我不是说凌驾,我只是想两者兼而有之。因此,首先将documentroot重定向到F:/Path/to/Project,然后应用位于F:/Path/to/Project/.htaccess的.htaccess文件。您仍然无意中使用mod\u alias指令重写mod\u rewrite。在重写的文件夹中,因此F:/Path/to/Project/.htaccesso不带
别名,你访问
F:/Path/to/Project/
目录和htaccess文件的URL是什么?当我把它全部(index.php和.htaccess)放在我的docroot中时,它工作得很好。在我创建别名并将文件移动到新服务器后,重写规则就不起作用了。如果你将其移动到文档根目录,它肯定会起作用。问题是htaccess文件的解释发生在URI路径到文件路径映射上。当您的别名目录位于文档根目录之外时,这种情况就会中断。谢谢您的回答:)这不是我所期望的行为。
DocumentRoot /var/www/example.com
Alias /myapp /var/www/example.com/myapp/public
<Directory /var/www/example.com/myapp/public>
    # (or in this dir's .htaccess)
    RewriteEngine On
    RewriteBase /public
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [QSA,PT]
</Directory>
DocumentRoot /var/www/example.com
<Directory /var/www/example.com/myapp>
    # (or in this dir's .htaccess)
    RewriteEngine On
    RewriteRule   (.*) public/$1 [L]
</Directory>
<Directory /var/www/example.com/myapp/public>
    # (or in this dir's .htaccess)
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [QSA,L]
</Directory>