Evan Kennedy
Evan Kennedy

Reputation: 4185

Rewrite domain.com/sub/ to sub.domain.com on other server

I see many questions about rewriting from sub.domain.com to a local domain.com/sub/ folder, but have not found any for a rewrite in the other direction.

Keep in mind sub.domain.com is not on the same server as domain.com.

When a user goes to domain.com/sub/, that must actually be pointing them to sub.domain.com without a redirect.

Is this possible?

Upvotes: 1

Views: 295

Answers (1)

anubhava
anubhava

Reputation: 785531

On domain.com enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^sub(/.*|)$ http://sub.domain.com$1 [L,R=301,NC]

UPDATE

As per the comments if you don't want original URL to change: This will require you to enable mod_proxy on domain.com:

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^sub(/.*|)$ http://sub.domain.com$1 [L,P,NC]

Upvotes: 3

Related Questions