首页 > 解决方案 > 在 AWS lightail LAMP 中向 htaccess 文件添加子域

问题描述

我正在使用 AWS Lightsail LAMP 实例来托管该站点。我想为其添加子域。经过大量搜索后,我无法自己修复它,需要一些帮助。

细节:

根域 --> 英文 -https://www.example.site/

我想将其他语言添加为子域。

子域 - 法语 -https://fr.example.site/
子域 - 德语 -https://de.example.site/

我已经完成了 vhost 配置并且 apache2 服务器从https://fr.example.site/https://de.example.site/成功地提供了测试页面

但是,当我使用 htaccess 部署实际应用程序时,根域工作正常,但子域导致以下错误

fr.example.site is currently unable to handle this request. 
HTTP ERROR 500

我的 htaccess 规则存在一些问题。

这是我现有的 htaccess 内容。

Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]


RewriteRule ^index.html$ index.php
RewriteRule ^(.*)-result.html$ result.php
RewriteRule ^2-letter-words-with-(.*).html$ twoletter.php
RewriteRule ^3-letter-words-with-(.*).html$ threeletter.php
RewriteRule ^words-starting-in-(.*).html$ wordstartedwith.php

我想为子域 fr 和 de 添加规则,以便从以下目录提供内容。

https://www.example.site/ --> /home/bitnami/htdocs/
https://fr.example.site/ --> /home/bitnami/htdocs/fr
https://de.example.site / --> /home/bitnami/htdocs/de

任何指针都会有很大帮助。

标签: amazon-web-services.htaccessmod-rewritelampamazon-lightsail

解决方案


使用您显示的示例,您能否尝试以下操作。请确保在测试 URL 之前清除浏览器缓存。

##For base site Rules.
RewriteCond %{HTTP_HOST} ^(?:www\.)example\.site [NC]
RewriteCond ^/?$
RewriteRule ^ home/bitnami/htdocs/ [L]

##For fr site Rules.
RewriteCond %{HTTP_HOST} fr\.example\.com [NC]
RewriteCond ^/?$
RewriteRule ^ home/bitnami/htdocs/fr [L]

##For de site Rules.
RewriteCond %{HTTP_HOST} de\.example\.com [NC]
RewriteCond ^/?$
RewriteRule ^ home/bitnami/htdocs/de [L]

推荐阅读