Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Redirect Sub--directory Request to Different URL

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
pkonstan1
Asked:
pkonstan1
  • 2
1 Solution
 
Marco GasiFreelancerCommented:
You can try this:

RedirectMatch 301 ^/en/.*$ http://www.newEnglishSite.com/$1
0
 
pkonstan1Author Commented:
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
 
Marco GasiFreelancerCommented:
Try this:
RedirectMatch 301 ^/[a-zA-Z]{2}/.*$ http://www.newEnglishSite.com/$1
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now