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


(Praan Kumar) #1

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

(Pradeep Kumar) #2

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

(Shashank Barthwal) #3

choose desired one as primary! :slight_smile:

(Praan Kumar) #4

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

(Praan Kumar) #5

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

(Pradeep Kumar) #6

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

(Praan Kumar) #7

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

(Pradeep Kumar) #8

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

(Praan Kumar) #9

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

(Praan Kumar) #10

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

(Praan Kumar) #12

In short

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