I already have a few rules set up redirecting users, like none www to www.
but google is still indexing the site ip address i would like this to be redirect to www.and the same if a user tried it
dose any one know how to write this in the htaccess file ??
Redirect any request where the host does not start with www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Related
I'm trying to redirect my non-www site to its www version, to this end I put the below code in the .htaccess in root folder of my site:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
But problem is that after all this configuration I get this error when trying to access it:
The page isn’t redirecting properly
Both www and non-www address of my site doesn't work.
Is anything wrong with that code?
This situation arises on a server that hosts multiple domains. Mostly such servers are shared hosts or reseller type of hosting arrangements. Use the following code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?example\.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
I've found the solution here
I've searched all over and I can find ways to direct www to non and the other route as well. But it feels like I have a bit of a different case.
I am trying to use a vanity URL to direct users to an alternate url and path. So that when a user enters www.vanityurl.com or vanityurl.com it directs them to domain.com/path/id
This is what I have
RewriteCond %{HTTP_HOST} ^test.com [OR]
RewriteCond %{HTTP_HOST} ^www.test.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/path/id/$1 [L,R=301,NC]
This works great for www. But, test.com either fails or redirects to just domain.com with out the path.
Help!?
I could redirect subdomain to subdirectory:
sub.domain.com > www.domain.com/sub
By using:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.domain.com [NC]
RewriteRule (.*) www.domain.com/sub/$1 [R=301,L]
However, the page at www.domain.com/sub displayed nothing but this:
Index of /sub
Parent Directory
Apache Server at www.domain.com Port 80
I have a working website with contents at sub.domain.com.
How can I load the same website and make it work at www.domain.com/sub ?
Thank you.
Jon is right, you need to move the content. Then you just need to fix your redirect by adding http:// in front of the target domain to redirect incoming requests from the old subdomain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/sub/$1 [R=301,L]
Can anyone suggest how I get non www traffic to redirect to the www version of a website using the htaccess file - I know I have one created in my root directory but cannot be sure what to put.. any ideas
Relatively easily.
Match anything that does not begin with 'www.' and then redirect to the 'www.' version:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I have a simple .htaccess which redirect non www to www domain
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
What I need to do is to exclude the IP calling from this redirect.
In other words I need that if someone call site by IP then it won't be redirected to www domain, it will call the IP itself and visitor can navigate all the site links without the 301 redirect. This means he will still navigate the site through the IP.
Try
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
It looks to see if the host does not start with www and if so it redirects to the www URL. It won't match the IP address or any other subdomains (i.e. test.example.com)