Jump to content

301 redirect, the right (SEO) way


Marco Angeli
 Share

Recommended Posts

Hi there,

I added a ssl certificate to my site and I'd like to redirect every single http url to its new https version

So I added this code in the .htacces file, after the RewriteEngine On :

Redirect 301 /about https://www.mysite.it/about

Unfortunately this is now working: I get the "too many redirects" error.

The following code works, but it's a bulk redirection to the home page, something I don't want for SEO reasons (https://moz.com/blog/save-your-website-with-redirects😞

RewriteCond %{HTTP_HOST} mysite\.it [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mysite.it/$1 [R,L]

Any suggestions?

Link to comment
Share on other sites

 # -----------------------------------------------------------------------------------------------
  # 9. If you only want to allow HTTPS, uncomment the RewriteCond and RewriteRule lines below.
  # -----------------------------------------------------------------------------------------------
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  
  # If using an AWS load balancer, use these two lines below instead of those above:
  # RewriteCond %{HTTP:X-Forwarded-Proto} =http 
  # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 

Link to comment
Share on other sites

Hey guys,

thanks for pointing me to the PW htaccess code. I wasn't aware of it.

Anyway that code is a bulk redirection of all existings http urls to to the home page. I would avoid it for seo reasons. I found many advices that suggest to redirect the single http page url to the equivalent https page url.

For example, if I needed to redirect the about page:

Redirect 301 /about https://www.mysite.it/about

Unfortunately that code doesn't work in the default .htaccess file  (Too many redirects error), and I don't know why.

Maybe some of you already found a solution?

Link to comment
Share on other sites

It's not a bulk redirection of all to home...

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

All urls redirect to its same url just https.

Your code doesn't work and doesn't make sense here at all cause you redirect /about to /about to /about to /about to /about .....

Link to comment
Share on other sites

  # -----------------------------------------------------------------------------------------------
  # 9. If you only want to allow HTTPS, uncomment the RewriteCond and RewriteRule lines below.
  # -----------------------------------------------------------------------------------------------
  # RewriteCond %{HTTPS} off
  # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This part of the .htaccess works absolutely perfect - at least for all my ProcessWire powered sites which are a few now.

Too many redirects is most likely a caching problem in your browser. Try it in a private/incognito window again.

If this doesn't change the wrong behaviour try a Google search for similar problems with your hosting company. Some hosting companies do weird things sometimes.

If you are using any kind of CDN (for example: Cloudflare) disable caching, routing or forcing https and enable debug/developer mode.

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...