ShanjayG
ShanjayG

Reputation: 1023

Htaccess Multi domain, but redirect one domain except a specific path

I have a multi-domain configured htaccess which means depending on what domain name is entered, the depending content is displayed and is redirected to the https version of whatever domain

A small snippet of my what I tried in my .htacess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^arabme.com$ [NC]
RewriteRule ^(.*)$ https://www.arabme.com$1 [R=301,L]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^chiname.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(landing|marketing)
RewriteRule ^(.*)$ https://www.greatwall.com$1 [R=301,L]

but on chiname.com I want to redirect all to http://www.greatwall.com except for two folders. /landing and /marketing.

So whenever a user enters chiname.com/landing/*.php or chiname.com/marketing/*.php it needs to display without redirecting to the https://www.greatwall.com and for every other path regarding chiname.com needs to redirect to https://www.greatwall.com.

My above would always redirect to https://www.greatwall.com/ regardless of my rewriteCond when I access any of the /landing or /marketing folders from chiname.com.

Note I do not have Server level privileges so I do not have access to the VirtualHost .conf files.

Upvotes: 0

Views: 54

Answers (1)

CD001
CD001

Reputation: 8472

Arguably it would be better to do this in a <VirtualHost> directive in the main httpd-vhosts.conf file - but since that's not an option:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^arabme.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.arabme.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^chiname.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(landing|marketing)
RewriteRule ^(.*)$ https://www.greatwall.com/$1 [R=301,L]

Assuming your .htaccess file is at the document root, you just had a couple of errors:

1: you don't need to repeat RewriteEngine On

2: you'd missed a / after greatwall.com in the RewriteRule which meant the redirect would go to https://www.greatwall.comwhatever rather than https://www.greatwall.com/whatever


I tested this on htaccess.madewithlove.be so it should work.

Upvotes: 1

Related Questions