如何重写主域上的子域 url?

How to rewrite sub domain urls on main domain?

我需要帮助来配置我的 htaccess。我需要将所有子域 url 重新写入主域。

这是我的 htaccess:

 RewriteEngine On

 Options +SymLinksIfOwnerMatch

# http => https
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# add www to main domain
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]

# language subdomains handler
RewriteCond %{QUERY_STRING} !(?:^|&)lang= [NC]
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.
RewriteRule ^ %{REQUEST_URI}?lang=%1 [QSA,L]

我还有其他像这样重写的网址:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^about/$ /about.php [NC] 

此页面在主域上运行良好。 https://www.example.com/about/

但在子域中我收到 404 错误。 https://en.example.com/about/

谁能指导我如何解决它?

PS: 这是与以下相关的另一个问题:

谢谢

您可以像这样拥有完整的 .htaccess:

Options +SymLinksIfOwnerMatch
RewriteEngine On

# http => https
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# add www to main domain
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]

# language subdomains handler
RewriteCond %{QUERY_STRING} !(?:^|&)lang= [NC]
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.
RewriteRule ^ %{REQUEST_URI}?lang=%1 [QSA]

# php extension handler e.g. /about/ => /about.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ .php [L]