How to fix redirecting and Indexing both www and non-www versions?



I had bought an php JavaScript web application from codecanyon. But it start indexing with both www and non www versions. When I type www, it opens with www if I type non-www then also, it opens with that! it is and


@praankumar bro, which version do you want as default? www or non-www? :slight_smile:


choose desired one as primary! :slight_smile:


Non www bro, its short. Where/which file to redirect /edit ?


But Solution? That what I am trying, its a php script bro, you can’t just choose other CMS like WordPress, etc.


It doesn’t matter bro, in the root directory, do you have .htaccess file for this domain? :slight_smile:


Ya, I have bro, how to fix with .htacces bro?


You can use this code to redirect www to non-www bro:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Kindly take a backup of your .htaccess file before proceeding bro, just to be safe. :slight_smile:

HELPFUL: HTACCESS useful Rewrite Codes


Thank you bro a lot. I will do the same.


This done my job

RewriteEngine on

if a directory or a file exists, use it directly

RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

otherwise forward it to index.php

RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Thank you Pradeep bro a lot


In short

   RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule ^(.*)$$1 [L,R=301]