Force the trailing slash in 1 redirect

#556109
  • Resolved Anonymous
    Rank Math free

    hello, i have read and implemented your guide on https://rankmath.com/kb/how-to-redirect-to-urls-with-trailing-slash/ and i have added the code you suggest into my htaccess file. the code works, and it forces the trailing slash, however when i use a redirect checker, I see that it first redirects to HTTP and then back to HTTPS. I know having this many redirects is not good for SEO. can you please help me figure out how to force the trailing slash with 1 redirect instead of having to redirect to HTTP first? Thanks

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hello,

    Thanks for contacting us, and sorry for any inconvenience that might have been caused due to that.

    Can you please share your site URL with us? So that we can investigate the issue further for you.

    Looking forward to helping you.

    Thank you.

    Anonymous
    Rank Math free

    yes, the URL is https://mentalismhub.com/best-cold-reading-techniques (no trailing slash)

    it gets redirected to the correct page which is https://mentalismhub.com/best-cold-reading-techniques/ (with trailing slash)

    However if you use a redirect checker such as https://kinsta.com/tools/redirect-checker/ or any others, you will see that it gets redirected to HTTP first and then back to HTTPS. This is an unnecessary redirect. I’d like it to be done in one redirect and not get redirected to HTTP first because unnecessary redirects such as the case here is not good for page speed and the search engines. Search engines don’t like too many redirects.

    I am using the code that I found on your article here: https://rankmath.com/kb/how-to-redirect-to-urls-with-trailing-slash/

    Hello,

    In this case, please share your .htaccess codes so we can check the redirects on your site. You can use this tool to paste the codes and share here the generated link.

    Looking forward to helping you.

    Thank you.

    Anonymous
    Rank Math free

    yes of course, here is my entire htaccess file

    https://pastebin.com/xiL653bN

    Hello,

    Please try removing the current directives you have for the HTTPS and slash redirection and include the following instead:

    
    RewriteEngine On
    
    # Redirect to HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Add trailing slash
    RewriteCond %{REQUEST_URI} /+[^\.]+$ 
    RewriteCond %{REQUEST_URI} !^/wp-json
    RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
    

    This should prevent the redirections from going between HTTP and HTTPS when the correct variation is already set.

    Don’t hesitate to get in touch if you have any other questions.

    Anonymous
    Rank Math free

    can you tell me what exactly i am supposed to remove? am i suppose to remove the prettylinks part too?

    I try to delete just the trailing slash part and add what you wrote, and that didn’t work. the website wouldn’t load.

    so i also tried removing the pretty links SSL redirect and add what you wrote, and that didn’t work either.

    both scenarios broke my site and i got the error “too many redirects” when trying to load my site

    Hello,

    Please try removing the code from line 1 to 18 in the pastebin link you have shared.

    From # Force trailing slash to #End Really Simple SSL Redirect

    Then, please add the codes from my colleague above in the .htaccess file.

    Let us know how this goes.

    Thank you.

    Anonymous
    Rank Math free

    Hello, I tried what you suggested, and now my website won’t work. it tells me “too many redirects” when I try to go on my website.

    Here is my current htaccess file

    https://pastebin.com/ScqsGwY3

    Hello,

    To help you further and investigate the issue thoroughly, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Anonymous
    Rank Math free

    I have added the temporary login link to the sensitive data area. please let me know if you make any changes. Thank you.

    Hello,

    Your website is using the Yoast SEO plugin and this forum is for support related to the Rank Math plugin.

    Regarding the .htaccess you have duplicate redirections on it for the trailing slash, so you will need to remove the duplicates and make sure only one redirection is triggered for this feature.

    If you are not sure, you might need to hire a developer that is experienced with this as supporting websites that have another SEO plugin is outside the scope of our support.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 11 replies - 1 through 11 (of 11 total)

The ticket ‘Force the trailing slash in 1 redirect’ is closed to new replies.