Skip to main content

Posts

Showing posts with the label redirect

Redirect www to non www url using htaccess

 Redirect www to non www url using htaccess   sSometimes we can access our website on both url like https://www.learncodetoday.com and https://learncodetoday.com , but its not good for SEO. So today we will learn how can we redirect a user from www to non-www url using htaccess. .htaccess file is a routing file that you can find on your project root folder and if its not exist there then you can create a .htaccess file there. Copy and paste below code into your .htaccess file for redirection RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteCond %{ENV:HTTPS} !on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] Now save file and try to open your website by using www url and it will auto redirect you on non-www url. Related Links How to remove www from url .htaccess to redirect an url Redirect my domain from www to non www domain url