我目前正在尝试在一个子文件夹中启动一个新版本的web平台,以便它可以与现有平台共存。
例如:
https://subdomain.example.com/ <--当前版本
https://subdomain.example.com/v3/ <--新版本
目前的版本是angularJS应用程序,新版本是Vuejs。该平台使用弹性豆茎托管在AWS上。
我现在的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>新应用程序会编译到一个名为v3的文件夹中。
偶尔,当我访问https://subdomain.example.com/v3/时,我会看到新版本的web应用程序。其他时候,我得到了一个403错误。
每当我尝试转到需要直接使用vuejs路由器(v3)处理的路由时,apache都会返回403。例如https://subdomain.example.com/v3/auth/login。
但是,访问/v3/本身会将我转到/v3/auth/login并显示正确的内容。
另一个问题是https的重写不再起作用,并允许非https连接。
这里的任何帮助都将不胜感激!
发布于 2019-07-31 10:40:41
首先,您希望在使用重写规则时禁用MultiViews。您可能还想禁用自动索引,因此这将是Options -Indexes +FollowSymLinks -MultiViews。
因为您有一个重写规则,所以实际上可以完全避免别名,并重写到完整路径。这将使事情变得更容易管理。
类似于:
RewriteRule v3.*$ /var/app/current/new-app/v3/index.html [L]
该规则需要存在于您的"main“(与您的DocumentRoot相关的内容) Directory指令中,因为您不会像对您的别名那样访问实际的v3路径本身。
重写规则的重写部分应该是一个有效的URL,而它可能只是一个有效的服务器路径,这是一个常见的误解。这里有一个有趣的观点:Force a URL-path for mod_rewrite's RewriteRule Substitution
HTH
https://stackoverflow.com/questions/57280619
复制相似问题