我已经浏览并尝试了许多不同的建议,但都无济于事。请帮忙!
我想将所有子域重定向到主域。我已将通配符子域的DNS指向带有A区域的IP,当前输入的任何子域都将导致404。我的最终结果是,对于任何子域及其URL,它将被重定向到主域。即
blog.my-domain.com
-> my-domain.com
(是,我的网域带有破折号)
test.my-domain.com/testing
-> my-domain.com
example.my-domain.com
-> my-domain.com
我当前的.htaccess文件如下:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# DO NOT REMOVE THIS LINE AND THE LINES BELOW SSL_REDIRECT:my-domain.com
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^my-domain.com$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE SSL_REDIRECT:my-domain.com
我尝试在底部添加这段代码,但没有成功
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.my\-domain\.com$ [NC]
RewriteRule (.*) https://my-domain.com%{REQUEST_URI} [L,R=301]
请帮助谢谢!!
答案 0 :(得分:1)
1)在“#BEGIN WordPress”行之前添加此规则
'amis.${numeroSender}'
这是1:1重写示例:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^my-domain.com$ [NC]
RewriteRule ^(.*)$ https://my-domain.com/$1 [R=301,L]
2)另一种可能性是仅为子域添加规则,将其添加到“#BEGIN WordPress”行之前
(http or https)://any-subdomain.my-domain.com/link <> https://my-domain.com/link
它将所有子域请求重写为my-domain.com,例如:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.my-domain\.com$ [NC]
RewriteRule ^(.*)$ https://my-domain.com/ [R=301,L]
选中您更喜欢的选项。