Plik htaccess, którego używam, zawiera
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don"t put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Ten kod pomaga w przekierowaniu adresu URL z przyklad.com do https://www.example.com
Problem polega na tym, że przekierowuje również subdomeny https://www.sub.example.com
Chcę, aby subdomeny przekierowywały tylko na http://www.subdomain.example.com
Odpowiedzi:
2 dla odpowiedzi № 1Możesz użyć a RewriteCond
w http->https
reguła, aby ograniczyć ją tylko do domeny głównej:
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don"t put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]