Redirect WWW Version to Non-WWW Version

#314508
  • Resolved Irene RF
    Rank Math free

    Happy holidays!!
    Sorry that I am coming at such inadequate moment.

    I have the following redirect with Cloudflare, but I have to set up this in the haccess file now .

    It’s only a redirect for the home page:
    example.com redirects to example.com/es/

    I saw your KB however this is a bit different, and I don’t want to mess up the live site. https://rankmath.com/kb/how-to-redirect-www-urls-to-non-www/

    Should this work, or has to be a completely different thing?
    1)

    RewriteEngine On
    RewriteCond %{HTTP_HOST} www.example.com
    RewriteRule (.*) https://example.com/es$1 [R=301,L]

    OR

    2)
    Is the above redirect ok or it must have a slash after /es/

    RewriteEngine On
    RewriteCond %{HTTP_HOST} www.example.com
    RewriteRule (.*) https://example.com/es/$1 [R=301,L]

    I will be very grateful if you could help!
    Thanks
    Irene

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

    Thank you for contacting Rank Math today.

    The 2nd code should work for the redirection:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} www.example.com
    RewriteRule (.*) https://example.com/es/$1 [R=301,L]

    Hope this helps.

    Looking forward to helping you. Thank you.
    ​​​​​​

    Thanks Kamlesh,

    I tried also with:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.website.com [NC]
    RewriteRule ^(.*)$ https://website.com/es/$1 [L,R=301]

    I set this up on top of the htaccess file
    And is not working

    I had to restablished the Cloudflare redirect.
    Any other suggestion

    Hello,

    I’ve checked the site, and it’s already redirecting to the /es/ version. Please refer to the screenshot attached in the sensitive data section.

    Could you please try clearing your website and browser’s cache?

    I hope that helps.

    Thank you.

    As I said this is redirected by a Cloudflare page rule that I had setup before.

    Now I have to setup the redirection in the htaccess file because I have to pausse Cloudflare.

    I disable/enable to check the htaccess redirect.

    As the htaccess redirect doesnt work, I enable the Cloudflare page rule again.

    I use Cloudways, I think that maybe not everything works the same that in other servers.

    About this
    7. Redirection of Domain to a Subdirectory
    I am not sure I only want to redirect the homepage not all the rest.

    I tried this too

    RewriteEngine On 
    RewriteCond %{HTTP_HOST} !^domain\.com [NC,OR]
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^(.*)$ https://domain.com/es/$1 [R=301,L]

    Nothing works

    Hello,

    If you only want the redirect to be applied to your homepage, please try using either one of these:

    RedirectMatch 301 ^/$ https://newsite.com/es
    

    or

    RewriteEngine On
    RewriteRule ^$ https://newsite.com/es [L,R=301]

    Then add the code snippet after the #END WordPress line in your .htaccess file.

    Furthermore, you can get in touch with your web host for this kind of redirect as they are in a better position to help you with this.

    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 8 replies - 1 through 8 (of 8 total)

The ticket ‘Redirect WWW Version to Non-WWW Version’ is closed to new replies.