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
Solved

Redirect Sub--directory Request to Different URL

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 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 …

856 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