Solved

Redirect Sub--directory Request to Different URL

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

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 30

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help cleaning out CSS 2 29
sql sentence 2 12
SQL inner join confusion 15 21
Why does my array not "dump?" 5 19
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now