问题描述
我有两个域。
farrwest.com(在 3000 端口运行 vuestore,在 8080 端口运行 vuestore-api)
和
dev.farrwest.com(在端口 3001 上运行 vuestore)
我在两个域的根目录中添加了带有重写规则的 .htaccess
。
使用以下配置。
farrwest.com:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^api(.*)$ http://localhost:8080/api$1 [P,L]
RewriteRule ^img/(.*)$ http://localhost:8080/img/$1 [P,L]
RewriteRule (.*) http://localhost:3000/$1 [P,L]
dev.farrwest.com:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} dev.farrwest.com
RewriteRule (.*) http://localhost:3001/$1 [P,L]
两个站点都加载正常,除了在加载之前它们转到 404 页面未找到,然后页面被加载。
我会在 apache 虚拟主机上使用反向代理,但我在 cpanel 中找不到它的配置。
使用 htaccess 我试图找到解决方法,但没有找到任何解决此问题的方法。
解决方法
找到解决方案:
更新了我的 .htaccess 文件如下。
farrwest.com:
DirectoryIndex
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^api(.*)$ http://localhost:8080/api$1 [P,L]
RewriteRule ^img/(.*)$ http://localhost:8080/img/$1 [P,L]
RewriteRule ^(.*)?$ http://localhost:3000/$1 [P,L]
dev.farrwest.com:
DirectoryIndex
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} dev.farrwest.com
RewriteRule ^(.*)?$ http://localhost:3001/$1 [P,L]