Solved

Redirect Sub--directory Request to Different URL

Posted on 2014-04-09
3
351 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
  • 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't connect to WAMP server 5 54
php convert date format 3 24
PHP-Client-Registration-Login article and  saving last last login 6 31
PHP not parsing ' character 12 40
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

832 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