I wanted to rewrite any request with http://www.example.org, https://www.example.org and http://example.org to https://example.org
Is there an easy way to do it?
I am currently doing the following in my .htaccess however the case of https://www.example.org -> https://example.org is not working.
- Any ideas where I could be going wrong?
- Also would it affect any search engine rankings because of this redirection.
- Is this a best practice in URL redirection.
My current .htaccess looks like this.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.org
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://example.com%{REQUEST_URI}
</IfModule>
Thanks
Try this in your .htaccess file:
R=301will redirect with https status 301Lwill make last ruleNEis for no escaping query stringQSAwill append your existing query parameters$1is your REQUEST_URI