Redirect all webpages to www with .htaccess - .htaccess

I've been trying to redirect my subdomain pages to force them to be at www.
The thing is, if I try example.example.com it will perfectly redirect to www.example.example.com, in the other hand, if I try example.example.com/whatever.html it won't redirect. My .htaccess file looks something like this:
RewriteEngine On
#subdomain non-www to www
RewriteCond %{HTTP_HOST} ^example.example.com$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]
Any ideas? Thanks guys!

Try removing the $ from the RewriteCond line.

Related

Redirect non www to www sub pages also

in .htaccess Am using :
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/$1/ [R=301,L]
It works fine for main domain i.e. redirects example.com to https://www.example.com
but not works on sub pages like
site.com/blog not redirects to https://www.example.com/blog
also like to add tailing slash '/' after url
https://www.example.com/blog/
how to achieve this?
Thanks in advance!
You should have htaccess rule like this. Make sure you keep these rules at the top of your htaccess file. Please clear your browser cache before testing your URLs.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}/ [NE,R=301,L]

How can I redirect a subdomain to a specific URL?

I am updating the Iirf.ini file to redirect sub.columbia.edu to giving.columbia.edu/video.
sub.columbia.edu is already redirecting to giving.columbia.edu.
How can I go one step further to redirect it to giving.columbia.edu/video.
Important Note: I would like the URL to show as sub.columbia.edu in the browser and not as giving.columbia.edu/video
#Redirect subdomain to specific URL
RewriteCond %{HTTP_HOST} ^sub\.columbia\.edu
RewriteRule ^/$ /video
The above doesn't work. Any ideas how I should modify this?
Thank you!
You can try this and see how it works for you.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.columbia\.edu
RewriteRule ^(.*) http://giving.columbia.edu/video [L,R=301]
Or you can do a redirect, this should work also.
Redirect 301 / http://giving.columbia.edu/video

htaccess 301 redirect is not working properly

I would like to make a redirect from http://www.jobslanda.com to http://www.jobslanda.com/
I'm trying to use this code in htaccess but it is not working.
Redirect permanent /http://www.alexandria-garagedoor.com http://www.alexandria-garagedoor.com/
Try:
RewriteCond %{HTTP_HOST} ^jobslanda\.com$
RewriteRule ^(.*)$ http://www.jobslanda.com/$1 [L,R=301]

.htaccess redirect non-www to www problem

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.

htaccess sitea.com/1 to siteb.com/1

i want to create with htaccess that if you go to www.website1.com/page.php that you go to www.website2.com/page.php, and www.website1.com/foo/bar/index.php to www.website2.com/foo/bar/index.php redirects. How can i do that with htaccess? Example please.
If mod_rewrite is available, you can put this code into the .htaccess of www.website1.com:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?website1\.com$
RewriteRule ^(.*)$ http://www.website2.com/$1 [L,QSA,R=301]
This would redirect every page on website1.com to the equivalent on website2.com

Resources