Solved

Redirect Sub--directory Request to Different URL

Posted on 2014-04-09
3
355 Views
Last Modified: 2014-04-22
I am trying to set up a redirect rule in my .htaccess file and I'm needing some help to get it to work.

I want people who reference a sub-directory to redirect to a different domain. For example:

www.myMainSite.com/en should redirect to: www.newEnglishSite.com

I've gotten close, but I'm shooting in the dark. I've just tried to apply a few things I read elsewhere, but it's crashing so something is wrong.

Can you tell me how the .htaccess file needs to be configured?

RewriteCond %{HTTP_HOST} *./en$ [NC]
RewriteRule ^(.*)$ http://www.newEnglishSite.com/$1 [L,R=301]

Thanks.
0
Comment
Question by:pkonstan1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39992212
You can try this:

RedirectMatch 301 ^/en/.*$ http://www.newEnglishSite.com/$1
0
 

Author Comment

by:pkonstan1
ID: 39993314
Thank you. This makes sense and works, but here's a follow-up question.

Is there any way that you can think of where you could have any a redirect match based on a sub-folder reference with only two characters.  So if somebody used,

www.myMainSite.com/en
www.myMainSite.com/ft
www.myMainSite.com/ch
www.myMainSite.com/de

I would like all of these to trigger a match that would then forward to a new site. So is there anyway to change the redirect to match a number of characters?

RedirectMatch 301 ^/(2 character match)/.*$ http://www.newEnglishSite.com/$1

Where "2 character match" would be matched in the above characters because the subdirectory contains two characters?

Thanks.
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 225 total points
ID: 39993358
Try this:
RedirectMatch 301 ^/[a-zA-Z]{2}/.*$ http://www.newEnglishSite.com/$1
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question