Jump to content

.htaccess - redirect to https://www.*** but not have the www. if it's a subdomain


Recommended Posts

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.