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

with the help of the above code, I am able to redirect https://example.com/ to https://www.example.com/

but when I open https://example.com/page.html in the browser it doesn't redirect to https://www.example.com/page.html

I am using www in canonical tag, and sitemap.xml but Google still indexes the wrong URL (the one without www url) so I want when the user opens (https://example.com/page.html ) it should redirect to (https://www.example.com/page.html).

  • What does "not working" mean here? Please post exact request, expected result and actual result. Aug 7, 2021 at 7:27


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.