0

I have hosted multiple websites on my server all sharing the same code base having one htaccess.

I need something like this.

if (domainname != example.com) redirect to example.com

if there any way of handling this from htaccess

used the following but still it is not working

RewriteCond !^(.*)$ https://example1.com/$1 [NC] 
RewriteRule ^(.*)$ https://example2.com/$1 [R=301,NC,L]
Harish Ninge Gowda
  • 153
  • 1
  • 2
  • 6
  • As per @krt I used. Still not working RewriteEngine on RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://talentpark.net/$1 [L,R=301] RewriteCond %{SERVER_PORT} 443 RewriteCond %{HTTP_HOST} ^www[.].+$ RewriteCond %{HTTP_HOST} !srishakthi.org$ [NC] RewriteRule ^(.*)$ https://talentpark.net/$1 [L,R=301] RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteBase / – Harish Ninge Gowda Apr 27 '16 at 15:19

1 Answers1

1

Adding the below apache rewrite rules should do the trick for you.

RewriteEngine On
RewriteBase /

# first redirect
RewriteCond %{HTTP_HOST} !domain.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]

# second redirect
RewriteCond %{HTTP_HOST} !example1.com$ [NC]
RewriteRule ^(.*)$ https://example2.com/$1 [L,R=301]

The above rules will do a 301 redirect of:

domain.com --> newdomain.com

and

example1.com --> example2.com

For each domain you want to be redirected use seperate RewriteCond and RewriteRule.

krt
  • 264
  • 2
  • 12