1

I'm trying to make all versions of homepage URLs 301 to same place, without a 301.

It's difficult to show the problem because I don't have enough rep points to post image or show the http response codes in a chart (too many links!)

But, using the code below https://www.example.com/ goes to http://www.example.com/ first, before it 301s to the homepage URL http://example.com

I'm on apache, and I've been using .htaccess to try to resolve this.

I've tried also tried the following, but it only works for file paths. Redirect 301 /oldfile.htm /newfile.htm

# Redirect HTTPS to HTTP
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example/$1 [L,R=301]

I've tried also tried the following, but it only works for file paths.

Redirect 301 /oldfile.htm /newfile.htm

Is there a way I can make https://www.example.com/ go to http://example.com without the 301 chain?

Thanks, Mike.

Jed
  • 21
  • 2

1 Answers1

0

You can use a single rule to redirect your https URLs to http and non-www version. This will redirect all of your https urls to http without creating multiple redirect chain.

Replace your htaccess rules with this :

# Redirect HTTPS to HTTP and non-www
RewriteCond %{HTTP:X-Forwarded-Proto} =https [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [L,R=301]

Make sure to clear your browser cache or use a different web browser to test this rule.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • Unfortunately it didn't change the www urls into non-www. It also seems to create a loop for hxxp://www.example.com/ I did also remove the escaping \ in the url too – Jed Oct 15 '19 at 16:08
  • @Jed I have updated the rule.test it after clearing your browser cache. – Amit Verma Oct 16 '19 at 02:13