简体   繁体   English

禁止使用Apache Alias

[英]Apache Alias forbidden

I'm currently in the process of trying to launch a new version of a web platform in a subfolder so it can co-exist with the existing platform. 我目前正在尝试在子文件夹中启动新版本的Web平台,以便它可以与现有平台共存。

eg 例如

https://subdomain.example.com/ <-- Current Version https://subdomain.example.com/ <-当前版本

https://subdomain.example.com/v3/ <-- New Version https://subdomain.example.com/v3/ <-新版本

The current version is an angularJS app and the new version is Vuejs. 当前版本是angularJS应用,新版本是Vuejs。 The platform is hosted on AWS with elastic beanstalk. 该平台托管在具有弹性beantalk的AWS上。

My apache config right now is 我现在的apache配置是

    <VirtualHost *:80>
       DocumentRoot "/var/app/current/current-app/releases/current"
        <Directory "/var/app/current/current-app/releases/current">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Require all granted
         RewriteEngine On
         RewriteCond %{HTTP:X-Forwarded-Proto} !https
         RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
         RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

         RewriteCond %{REQUEST_FILENAME} \.html$ [OR]
         RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
         RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
         RewriteRule ^ - [L]
         RewriteRule ^ /index.php
        </Directory>

        Alias "/v3" "/var/app/current/new-app/v3/"
        AliasMatch "^/v3/(.*)$" "/var/app/current/new-app/v3/$1"
        <Directory "/var/app/current/new-app/v3">
           Options Indexes FollowSymLinks MultiViews
           AllowOverride All
           Require all granted
           RewriteEngine On
           RewriteBase /
           RewriteCond %{HTTP:X-Forwarded-Proto} !https
           RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
           RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

           RewriteRule ^index\.html$ - [L]
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           RewriteRule . /v3/index.html [L]
        </Directory>
      </VirtualHost>

The new app compiles into a folder called v3 . 新的应用程序将编译到名为v3的文件夹中。

Occasionally when I visit the https://subdomain.example.com/v3/ i am presented with the new version of the web-app. 有时,当我访问https://subdomain.example.com/v3/时,会看到该Web应用程序的新版本。 Other times I'm given a 403 error. 其他时候,我得到403错误。

Any time I try to go to a route that needs to be handled with the vuejs router ( v3 ) directly, apache returns a 403. For example https://subdomain.example.com/v3/auth/login . 每当我尝试转到需要直接通过vuejs路由器( v3 )处理的路由时,apache都会返回403。例如https://subdomain.example.com/v3/auth/login

However, visiting /v3/ itself will forward me to /v3/auth/login and display the correct thing. 但是,访问/ v3 /本身会将我转发到/ v3 / auth / login并显示正确的内容。

Another issue is that the rewrite for https is no longer functioning and allowing non-https connections. 另一个问题是https的重写不再起作用,并且允许非https连接。

Any help here would be massively appreciated! 任何帮助将不胜感激!

First of all you want to disable MultiViews when using rewrite rules. 首先,您想在使用重写规则时禁用MultiViews You probably want to disable auto indexes too, so that would be Options -Indexes +FollowSymLinks -MultiViews . 您可能也想禁用自动索引,因此应该是Options -Indexes +FollowSymLinks -MultiViews

Since you have a rewrite rule, you could actually avoid the alias altogether and rewrite to the full path. 由于您具有重写规则,因此实际上您可以完全避免使用别名并重写为完整路径。 That would make things way easier to manage. 这将使事情更容易管理。

Something like: 就像是:

RewriteRule v3.*$ /var/app/current/new-app/v3/index.html [L]

That rule would need to live within your "main" (something in relation to your DocumentRoot ) Directory directive tho as you would not access the actual v3 path per se like you do with your alias. 该规则将必须存在于您的“主”目录(与DocumentRoot Directory )中,因为您实际上不会像使用别名那样访问实际的v3路径。

It's a common misconception that the rewritten part of a rewrite rule should be a valid URL, while it could just be a valid server path. 常见的误解是,重写规则的重写部分应该是有效的URL,而它可能只是有效的服务器路径。 There's an interesting take on this here: Force a URL-path for mod_rewrite's RewriteRule Substitution 这里有一个有趣的观点强制为mod_rewrite的RewriteRule替换提供URL路径

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM