【发布时间】:2021-12-20 16:53:47
【问题描述】:
我有一个外部域 example.com 在 GCP 中指向我的 ip。它设置了一个新服务器,并且在var/www/html 文件夹中有index.html 文件。我想要example.com/<any 6 digit unique string> 模式的任何 URL 来调用 index.html 文件。我尝试在.htaccess 文件中添加以下规则,并将其放在与index.html (/var/www/html) 相同的文件夹中。只有 URL example.com 呈现 index.html 文件,但 URL example.com/ha36hja 显示“未找到”错误。
这是我的.htaccess 文件:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} example.com [NC]
RewriteRule ^http://example.com(.*)$ index.html [R=301,NC]
【问题讨论】:
-
您提到了“6 位唯一字符串”,但您的示例显示了
subdomain.com/ha36hja,其中包含一个路径组件,其中的字符串肯定不是仅由数字组成 ... -
您是否在 Apache conf 中打开了带有
AllowOverride的.htaccess文件? -
而
example.com/ha36hja包含 7 个字符而不是 6 个字符的 URL 路径? -
修改了 apache.config 文件和 htaccess 到下面。修改后获取站点无法访问错误
RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} example.com/$1 [NC] RewriteRule ^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9]+{0,6}$ index.html [R=301,NC]和 apache.config<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> -
您需要使用该信息更新您的问题。但是那些 mod_rewrite 指令没有意义(特别是问题中的信息不一致)。 “无法访问站点”与“未找到”非常不同。但是您现在似乎也在编辑服务器配置,而不是
.htaccess?RewriteBase在 server 上下文中肯定没有位置,并且会破坏您的服务器。
标签: .htaccess redirect subdomain wildcard