I have a shared hosting plan so my website is located in: /public_html/example.com/
The .htaccess is located in the root folder /public_html/
I want to redirect example.com to www.example.com
so far, I've used
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
When I use my browser on example.com/test/ it directs to www.example.com/example.com/test/
How can I fix that?
Related
I had a subdomain https://sub.rootdir.com/ which was migrated to the root domain and to a new host.
I want to redirect this subdomain to the root folder. The host told me to re-create the subdomain and then create an '.htaccess' file in which you can set redirection rules such as:
Redirect 301 / https://rootdir.com/
I have kind of no idea what to type in the htaccess file.
Can I please get help from you?
Create a .htaccess file in your subdomain folder and enter this code in;
RewriteEngine On
RewriteCond %{HTTP_HOST} !^rootdir\.com
RewriteRule (.*) https://rootdir.com/$1 [R=301,L]
I figured it out from other posts here tx
#mod_rewrite on
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.rootdir.com$ [NC]
RewriteRule ^(.*)$ https://www.rootdir.com%{REQUEST_URI} [R=301,NC,L,QSA]
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 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)