jasonc310771 Posted June 6, 2023 Share Posted June 6, 2023 RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] The code above is what I currently have in the public_html folder. I have the just the first rewrite part of the code in the sub.domain.com's .htaccess file, but the url gets rewritten with the www. added. How do I stop the www. being added ? tia. Quote Link to comment https://forums.phpfreaks.com/topic/316943-htaccess-redirect-to-httpswww-but-not-have-the-www-if-its-a-subdomain/ Share on other sites More sharing options...
requinix Posted June 6, 2023 Share Posted June 6, 2023 This is an Apache question and not a PHP question, so now we're in the Apache forum. 1. Use SERVER_NAME instead of HTTP_HOST. After making sure your server is configured with the correct domain as the canonical name. 2. Instead of checking for https in one redirect and www in another, do both at the same time: if HTTPS is off or the HTTP_HOST != SERVER_NAME then redirect to the SERVER_NAME + REQUEST_URI. Quote Link to comment https://forums.phpfreaks.com/topic/316943-htaccess-redirect-to-httpswww-but-not-have-the-www-if-its-a-subdomain/#findComment-1609423 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.