如何重写主域上的子域网址? [英] How to rewrite sub domain urls on main domain?

查看:42
本文介绍了如何重写主域上的子域网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need a help with configuring my htaccess. I need to re-write all sub domain urls to main domain.

这是我的 htaccess:

This is my 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]

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

I have other re-writed urls like this:

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/

This page works fine on main domain. https://www.example.com/about/

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

But in sub domain I get 404 error. https://en.example.com/about/

谁能指导我如何修复它?

Can anyone guide me how to fix it ?

附注:这是另一个与以下相关的问题:如何配置多种语言通过 htaccess 和子域作为 GET 方法?

PS: It is another question related to : How to configure multiple languages via htaccess and sub domains as a GET method?

谢谢

推荐答案

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

You can have your full .htaccess like this:

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 ^(.+?)/?$ $1.php [L]

这篇关于如何重写主域上的子域网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆