When I enter my website address, it does not always put www. in front of it.
This is because I type domain.com instead of adding the www. in front as this is quicker.
What code do I have to use to make sure that even if I type domain.com it always adds the www. infront.
(I believe this has to do with .htaccess mod_rewrite function?
Thank you,
Chad.
In your .htaccess file, add the following lines (replacing mywebsite.com with your real website):
<IfModule mod_rewrite.c>
RewriteEngine On
#redirects all requests to www.mywebsite.com
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com
RewriteRule (.*) http://www.mywebsite.com/$1 [R=301,L]
</IfModule>
Note that as google recommands it is better to use a 301 redirection.
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com[nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Related
I am trying to redirect the following (respectively):
http://sub.firstdomain.com/d/(all_files_and_folders)
http://sub.firstdomain.com/d2/(all_files_and_folders)
to
http://sub.seconddomain.com/d/(all_files_and_folders)
http://sub.seconddomain.com/d2/(all_files_and_folders)
There are other files and folders under the first subdomain that I do not want redirected. Previously this was working but now it seems like Go Daddy changed something and what I had is no longer working. Here it is:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.+) /dstats/count.php?statspage=$1 [L,NC,QSA]
RewriteRule ^(.+)\.deb$ /dstats/count.php?file=$1.deb [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^sub\.
RewriteRule ^(d2?)/(.*)$ http://sub.seconddomain.com/$1/$2 [L,R=301]
You can ignore the RewriteRule. It is working fine. I wanted to make sure I included the entire .htaccess file just in case. My issue is with RewriteCond it seems.
The following should work:
RewriteEngine On
Redirect 301 /d/ http://sub.seconddomain.com/d/
Redirect 301 /d2/ http://sub.seconddomain.com/d2/
The above should only redirect anything in the /d/ and /d2/ folder of the sub subdomain.
EDIT: Second try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.
RewriteRule ^(d2?)/(.*)$ http://sub2.mydomain.com/$1/$2 [L,R=301]
I have a site example.com. Any traffic to www.example.com is redirected to example.com in the .htaccess file using:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
This piece of code that I swiped of the interweb works fine.
I have now added a subdomain subdom.example.com. Similar, any traffic to www.subdom.example.com should be redirected to the non www canonical version.
The following code does not work:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://subdom.example.com/$1 [R=301,L]
Presumably redirects work a little differently where subdomains are involved. Could anyone share how I would edit the above snippet to redirect any www. traffic to the canonical non www. subdomain version?
I believe you don't have sufficient RewriteCond conditions for both redirects. What is happening is that first one is unconditional redirect and since it appears first it always fires and 2nd one never fires.
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Above code will work with both of your domains.
Question is pretty simple I guess, but I fail to do this myself.
I have a website on http://website.com and want to 301 redirect ALL requests on www.website.com to http://website.com/ but make sure all directories and filenames stay the same (so not all requests end up at the homepage).
So whatever people may type (like www.website.com/something.here) should 301 redirect to website.com/something.here
How to do this?
Add the below to your .htaccess file. Should do the trick.
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
This requires that the rewrite engine is on...
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
</IfModule>
I have a site where regardless of what is placed instead of "www", the site still works:
ie. abc.example.com, w.example.com, wwww.example.com, ww.example.com, etc
What I need to do is redirect all of this to the "www" url.
Any help would be of great help
Regards,
Sushil
I think you're looking for something like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
This should rewrite any URL that someone goes to at "example.com" that does not begin with www to the URL with the www at the beginning. Note, you may choose to use <IfModule mod_rewrite.c> in the case the mod_rewrite is ever disabled or uninstalled.
I'm using the following .htaccess file to do few mod-rewrites and also redirect visitors from non-www to www. But the problem is, when someone visit http://domain.com/terms it redirects them to http://www.domain.com/document_terms.php by ignoring the 3rd line.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^terms$ document_terms.php
RewriteRule ^privacy$ document_privacy.php
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Is there a way to fix this?
You just need to change the order of your rules so the www rewriting comes first.