Redirect to https, non-www

Hello Everybody,

I’ve been using the following mod rewrite rule to force redirect of all http & www urls to https, non-www for years.

RewriteCond %{SERVER_PORT} 80 *
RewriteRule ^(.)$$1 [R=301,L,NE]

RewriteEngine On
RewriteBase /
already occur in a block before this rule.

I use these rules on the main domain as well as a subdomain that I use for a staging site (site .com & dev. site .com). Of course the dev site redirect points to the dev. site .com url… Both have been working for some time now I I have not changed them or modified any setting in my dreamhost panel.

Recently, I noticed via an ahrefs site report that www urls were resolving & not redirecting which results in “not indexable” pages due to a conflict with the canonical URLs and/or “duplicate” pages being indexed .

Either i’ve made a mistake or something has changed.

If I hit http:// www. site .com I get a single 301 redirect to https:// site .com. If I hit http:// site .com I get a single redirect to https:// site .com. This is all correct… However, if I hit https:// www. site .com I get no redirects and the https://www url resolves.

I’m aware of the Dreamhost panel control to set www, non-www or allow both but this rule worked before with that control set to “leave it alone” which allows either. I’ve experimented on the dev subdomain by setting it to redirect www to non-www. This works but it results in a series of 2 redirects which is not optimal & not the way it worked before. (at least not the way I thought it worked)

This might mean that my rule does not catch www explicitly or that it is being overridden by something in the httpd.conf file. I’m currently looking into the rule itself.

I’m no longer able to find any way to send an email to dreamhost support to address the issue and learn more so I’m posting here hoping that someone can help me out. Any clues would be greatly appreciated.

In the condition directive (RewriteCond %{SERVER_PORT} 80 *), what does the * flag do? I couldn’t find any doc about it.

Assuming the * is ignored, I don’t see how that rule could have ever redirected www to no-www. I would have expected two RewriteCond using the ornext flag to cover the two cases (port 80 or www).

Nowadays you can configure both redirects from the DH panel, so custom .htaccess rules are no longer needed in this case.

You can start a support request via:

Thanks. You might have found the issue. I believe the * was supposed to mean “anything” and so catch the www but I don’t think the * works in the place of a flag.

I did find the setting in the dreamhost panel to force https & already knew about the setting for non-www. I’ve activated both of those now & it is working but it results in 2 redirects instead of 1 if the user hits http://www. I should be able to do it in 1 shot.

The mysterious part is that it was working for about 2 years. Something may have changed on Dreamhost. I don’t think the panel setting to force https existed when I first installed the rule but the www/non-www setting definitely did and it has always been set to “leave it alone” to allow both.

I’m not sure how to format the condition with the ornext flag (researching now) would you be so kind as to provide an example?

When I use the panel redirects for both HTTPS and no-WWW, it seems to do a 1-shot redirect. Below is an example test using curl. If you’re seeing multiple redirects, then something is wrong.

$ curl -I
HTTP/1.1 301 Moved Permanently

$ curl -I
HTTP/1.1 301 Moved Permanently