通过.htaccess从子域中删除www.?

lsmd5eda  于 2022-12-13  发布在  其他
关注(0)|答案(2)|浏览(142)

我目前有以下哪些:
1.从url中删除www.并重定向到https://somedomain.com
1.将http://请求重定向到https://
这工作很好,这里是代码...

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我现在面临的问题是...如何从子域(例如https://www.subdomain.maindomain.com)中删除www.并将其重定向到https://subdomain.maindomain.com
希望有人能帮忙

rslzwgfq

rslzwgfq1#

试试看:

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]
ttp71kqs

ttp71kqs2#

要从子域中删除WWW,只需使用以下命令:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

相关问题