P. Pei
P. Pei

Reputation: 11

Use 301 redirect in htaccess on a server with multiple domain names to affect only 1 domain name

I have a server with 3 directories on it in the root and in the root with the 3 directories is a .htaccess file. Each directory points to a separate domain name.

I want to have 301 redirect code in the .htaccess file in the root so all files in xamplea.com redirect to https://xamplea.com with:

and

I tried:

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond xamplea.com ^www\. [NC]
RewriteRule ^ https://xamplea.com%{REQUEST_URI} [R=301,L,NE]

but the above also redirects xampleb.com and xamplec.com to https://xamplea.com when I only want xamplea.com to be redirected to https://xamplea.com.

Upvotes: 1

Views: 68

Answers (1)

Olivier
Olivier

Reputation: 254

Remove the [OR] in RewriteCond %{HTTPS} off [OR] since you want both conditions to be true in order to redirect. Also, your second condition is not valid, you probably want to check the domain name.

This would give you:

RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} xamplea\.com [NC] 
RewriteRule (.*) xamplea.com%{REQUEST_URI} [R=301,L,NE]

Upvotes: 1

Related Questions