Reputation: 4185
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
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]
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