【问题标题】:htaccess not work with virtualdocumentroothtaccess 不适用于 virtualdocumentroot
【发布时间】:2017-12-20 18:20:03
【问题描述】:

我想更改一个项目的根目录而不更改虚拟主机,但我的 htaccess 被忽略了

我的虚拟主机配置

/etc/apache2/sites-available/localhost.conf

<VirtualHost *:80>
   ServerAdmin email@example.com
   UseCanonicalName Off
   ServerAlias *.localhost
   VirtualDocumentRoot /var/www/%-2
   <Directory /var/www/%-2>
      Options FollowSymLinks
      AllowOverride All
   </Directory>
   ErrorLog /var/log/apache2/localhost-error.log
   LogLevel warn
   CustomLog /var/log/apache2/localhost-access.log combined
</VirtualHost>

和我的 htaccess

/var/www/test/.htaccess

RewriteEngine on
RewriteBase /build

已解决

我找到了解决办法

<VirtualHost *:80>
   ServerAdmin email@example.com
   UseCanonicalName Off
   ServerAlias *.localhost
   VirtualDocumentRoot /var/www/%-2
   <Directory /var/www/*>
      Options FollowSymLinks
      AllowOverride All
   </Directory>
   ErrorLog /var/log/apache2/localhost-error.log
   LogLevel warn
   CustomLog /var/log/apache2/localhost-access.log combined
</VirtualHost>

和htaccess

RewriteEngine on
RewriteBase !^build/ /build%{REQUEST_URI} [L]

现在 test.localhost 使用 /var/www/test/build 作为 root :)

【问题讨论】:

    标签: apache .htaccess virtualhost


    【解决方案1】:
       <Directory /var/www/%-2>
    

    您只能在 mod_vhost_alias 提供的指令中使用这种类型的变量,而不能在任何其他指令中使用。

    RewriteEngine on
    RewriteBase /build
    

    如果这是全部,这实际上并没有做任何事情。要查看文件是否被忽略,请向其中添加一些无意义的字符并确保它返回 ISE 500 错误。

    【讨论】:

      猜你喜欢
      • 2014-03-19
      • 2015-11-10
      • 2014-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-09
      相关资源
      最近更新 更多