Jump to content
Marco Angeli

301 redirect, the right (SEO) way

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?

Share this post


Link to post
Share on other sites

There's a special block in the PW htaccess commented out to redirect all requests to https if it's not.

Share this post


Link to post
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]

 

Share this post


Link to post
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?

Share this post


Link to post
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 .....

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Soma, you're right. It's a redirectict to a single url.

@ wbmnfktr: thanks for the explaination!

Problem solved. Thanks!

 

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By franciccio-ITALIANO
      Hi, we can choose the "headline" and "title" and "summery" in panel page of processwire, but we can't write the "metadecriptions" and "tags".
       I can write mdescropt and tags in templates, but I've same templates for many articles... so, how I can change mdescription and tags?

      Thanks...
    • By Orkun
      Hi Guys
      How can I make a redirect inside the .htaccess to my custom maintenance.html file when any URL of my Website is accessed except the processwire admin (www.example.com/processwire/).
      Because I want that my User's still can access the website when they are loggedin in Processwire.
      When the current url starts with /processwire or if there is a processwire-login-cookie (Is there a cookie when user is logged in Processwire?) available the redirect should not work. Otherwise it should work.
      How can I achieve this?
    • By Leftfield
      Hi All 🙂

      How to append canonical URL to head from certain templates?

      Thanks!!!
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I'm trying to automatically redirect a logged-in user to a custom profile page using $session->redirect() and need to add $user->name to the redirect path.
      All my attempts appear to have failed:
      $session->redirect('/user-profile/')->name; $session->redirect('/user-profile/')->$user->name; $session->redirect('/user-profile/' . get($user->name . '/')); $session->redirect('/user-profile/' & get($user->name)); Can anyone point out where I am going wrong?
    • By cosmicsafari
      Hi all,
      Just a quick question, when using the multisite module is there anything different that needs to be done in order to setup HTTPS for each of the domains its serving?
      Would a single SSL certificate for the main domain be enough to cover the others aswell or would you need multiple ceritficates one for each domain the mutlisite setup uses?
       
×
×
  • Create New...