How to force no-www URLs to www version URLs with htaccess?

For SEO reasons, you might always use (or remove) the www prefix in your urls. The following snippet will add the www to your website url and redirect any url with the  non-www to the www version.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^your-site.com [NC]
RewriteRule (.*) http://www.your-site.com/$1 [R=301,L]

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

DMCA.com Protection Status