FluffyKitten
FluffyKitten

Reputation: 14312

Is it possible to have separate domain alias & redirection depending on subdirectory?

I need to set up the aliasing/redirection of a domain name depending on whether its in a subdirectory or not.

newdomain.com is an alias for parent.com/newdomain. This is set up as an alias in the hosting control panel and is working.

I need the url to appear differently depending on the file, e.g

I can use htaccess to control redirection, but I haven't found a way for it to control aliasing. Is this possible? Thanks

Upvotes: 1

Views: 808

Answers (1)

anubhava
anubhava

Reputation: 785146

My answer is based on the assumption that newdomain.com and parent.com are being served from same Apache process.

Put this code in your .htaccess under DOCUMENT_ROOT directory of newdomain.com:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/+subdir/ [NC]
RewriteRule ^ http://parent.com/newdomain%{REQUEST_URI} [L,R=302,NC]

Once you verify that it's working then change R=302 to R=301

Upvotes: 0

Related Questions