仅使用.htaccess为主域和子域配置.htaccess

问题描述 投票:0回答:1

我有一个基于Apache 2.4和多个子域的www.main.com托管

呜呜呜.苏北1.卖弄.com, 呜呜呜.苏北2.卖弄.com, ....

文件夹结构是

/home/main/.htaccess + project files and subdomain folders like:
/home/public-html/main/sub1.main.com/.htaccess
/home/public-html/main/sub1/.htaccess + project1 files
/home/public-html/main/sub2/.htaccess + project2 files

等等

子域是基于不同技术的独立项目

/ home / main / website基于AngularJS并具有标准的角度.htaccess配置:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

我想在sub.main.com中有另一个.htaccsess配置,如下所示:

RewriteEngine On
RewriteRule ^$ http://127.0.0.1:3000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api$ http://127.0.0.1:3000/$1 [P,L]

哪个代理应该将我的Apache流量重定向到我的nodejs服务器。

在某些时候我的子域重定向不起作用。这仅适用于主文件夹。

所以我有3个问题:

  1. 我应该为主.htaccess中的所有域配置所有规则吗? (由于潜在的网址冲突,什么不是很好)
  2. 是否可以配置main .htaccess只是为了允许其他sub.domains使用自己的.httaccess
  3. .htaccess子域名的正确位置在哪里?

这里 - /home/public-html/main/sub1.main.com/.htaccess或这里 - /home/public-html/main/sub1/.htaccess + project1 files

这是一个共享主机,对apache配置的访问权限有限。我只能使用.httaccess方式,我没有权限更改我的虚拟主机,所以请仅提供.httaccess解决方案。

上面的两个代码片段都可以工作,并且不会重定向任何节点,但只能从home / main文件夹重定向,不能从子域重定向。

我需要每个子域特殊的.htaccess来托管多个项目

apache .htaccess redirect proxy subdomain
1个回答
0
投票

我找到了想要在共享主机上使用nodeJS的人的解决方案:

放到/ home / main / www / .htaccess下面:

RewriteEngine on

RewriteOptions inherit
RewriteCond %{HTTP_HOST} ^main\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.main\.org$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/.+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/angular\.main\.org\/" [R=301,L]

RewriteBase /
RewriteCond %{REQUEST_URI} !^/node/
# Rewrites all URLS node.main to node server
RewriteCond %{HTTP_HOST} ^(www\.)?node.main\.
# Redirect to node server
RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P, L]

里面/ home / main / www / angular put .htaccess像:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

并且我们在节点文件夹中不需要任何.htaccess我希望它对有相同问题的人有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.