Redirecting with the .htaccess

Posted on 23rd May, 2014 320 Comments

To redirect www to non www add this to your htaccess file.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

To redirect all sub-domains to the main domain use this.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.co.uk$   [NC]
RewriteRule ^ http://mydomain.co.uk/  [L,R]

To redirect a single sub-domain use this.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub-domain\.mydomain\.co.uk$   [NC]
RewriteRule ^ http://mydomain.co.uk  [L,R]

Redirect a single url/folder path

RedirectMatch 301 /old-path-to-file/wrong-path-to-file/(.*) /the-path-to-redirect-to/$1

There are a number of ace tools to help you generate your perfect htaccess file, below is the one I usually use.
www.webconfs.com/htaccess-redirect-generator.php

Comments

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]

VictorAmisp

17th, Oct, 20

incontestable to describe cytosine inconsiderable raspy with some bopping invertible. cialis online buy ” Immunosuppressant, Regimen Supervision of Routine, Miss Careful Comparisons.

JamesVen

21st, Oct, 20

latest HIV chatters volume digits who manifest recti through 78 [url=https://ciamedusa.com/]goodrx cialis[/url] ventricular contractions which have little found that does. <a href="

JamesVen

21st, Oct, 20

When acclimatized, if you’re reversed through reparative through your patient. [url=https://ciamedusa.com/#]cialis online pharmacy[/url] soil tests a means, the Patient of Late Route men’s.

Denny Basey

03rd, Jan, 21

This post will assist the internet visitors for building up new weblog or even a weblog from start to end.|

카지노사이트

11th, Jan, 21

Thanks for commenting, Viv. Hope this response of mine finds you doing well!
Good luck commenting on other sites you enjoy! Problogger, Boost Blog Traffic, and Carol Tice’s are great ones. Feel free to give mine (Be A Better Blogger) a look as well.
카지노사이트

hey

13th, Jan, 21

Taxi moto line
128 Rue la Boétie
75008 Paris
+33 6 51 612 712  

Taxi moto paris

Very good post. I absolutely appreciate this website. Keep writing!

windows loader vs kmspico

20th, Jan, 21

Everything is very open with a very clear clarification of the issues. It was definitely informative. Your website is extremely helpful. Many thanks for sharing!|

cheap flights

31st, Jan, 21

Hi there! I could have sworn I’ve visited this site before
but after browsing through a few of the articles I realized it’s new to me.
Anyhow, I’m definitely delighted I discovered it and I’ll be book-marking it and checking back regularly!

cheap flights

31st, Jan, 21

At this time I am ready to do my breakfast, afterward having my breakfast coming over again to read other news.

cheap flights

01st, Feb, 21

Hmm it seems like your site ate my first comment (it was super long) so I guess I’ll just sum it
up what I had written and say, I’m thoroughly enjoying
your blog. I as well am an aspiring blog blogger but I’m still new to everything.

Do you have any tips and hints for beginner blog writers?
I’d genuinely appreciate it.

cheap flights

01st, Feb, 21

Howdy! This post could not be written any better! Reading through
this post reminds me of my old room mate! He always kept chatting about this.
I will forward this article to him. Fairly certain he will have a good
read. Many thanks for sharing!

Life Experience Degree

02nd, Feb, 21

Unquestionably consider that that you stated. Your favorite justification seemed to be at the web the easiest factor to consider of. I say to you, I certainly get irked while people consider worries that they just do not know about. You controlled to hit the nail upon the highest and defined out the whole thing with no need side-effects , people could take a signal. Will likely be back to get more. Thanks

tinyurl.com

02nd, Feb, 21

Hey great website! Does running a blog similar to this require a massive
amount work? I have absolutely no understanding of computer programming but I was hoping to start my own blog
in the near future. Anyway, if you have any ideas or techniques for new blog owners please share.
I know this is off topic but I just needed to ask.

Cheers!

cheap flights

02nd, Feb, 21

A person essentially lend a hand to make seriously articles
I’d state. That is the very first time I frequented your web
page and up to now? I amazed with the analysis
you made to make this particular publish amazing. Wonderful activity!

tinyurl.com

03rd, Feb, 21

If you would like to obtain much from this paragraph then you have to apply
these techniques to your won website.

Life Experience Degree

04th, Feb, 21

Great goods from you, man. I’ve be mindful your stuff prior to and you are simply too excellent. I actually like what you have got right here, really like what you are saying and the way through which you assert it. You’re making it entertaining and you still take care of to keep it smart. I can’t wait to learn much more from you. This is really a wonderful website.

Charlesneape

05th, Feb, 21

browse tinder for free , tindr
[url=”http://tinderdatingsiteus.com/?”]browse tinder for free [/url]

zortilo nrel

07th, Feb, 21

Valuable info. Lucky me I found your web site by accident, and I am shocked why this accident did not happened earlier! I bookmarked it.

tadalafil

07th, Feb, 21

hair salon robber viagraOezpnho kokovmr viagra. smoking and blood pressure how is obesity related to type 2 diabetes, hypertension, and heart disease?.

cheap wigs

08th, Feb, 21

It’s very good, it’s not stuffy, it’s natural, it’s not a wig at all. I have seen many stores and bought many, but I am not satisfied. This release film is the most satisfying and will come next time. Five-star praise!

litespeed bypass

09th, Feb, 21

hello!,I really like your writing so a lot! percentage we keep up
a correspondence more approximately your post on AOL?
I need a specialist in this space to unravel my problem.

May be that is you! Having a look forward to look you.

tinyurl.com

12th, Feb, 21

It’s awesome in favor of me to have a website,
which is useful in favor of my know-how. thanks admin

Obacroli

13th, Feb, 21

juvenile idiopathic arthritis – cialis online Isgqnvz
should take half cialis
is viagra covered by health insurance: [url=https://www.withoutbro.com/]sildenafil[/url]

Leave a Comment

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]