Simple Problem - sub.domain.com rewrite to domain.com/sub

Using a single web hosting account to host multiple sites

Simple Problem - sub.domain.com rewrite to domain.com/sub

Postby Minty » Sun Jul 13, 2008 5:25 am

Hello, I'm having trouble with a relatively simple (and, I expect, common) problem rewriting (i.e.) http://sub.domain.com/whatever to http://domain.com/sub/whatever.

I tried something like:

Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\..*$
RewriteRule (.*) domain.com/sub/$1


However this alters the visble URL (the one in the address bar) which I'd like to keep as sub.domain.com/whatever...

Is this possible?

Any help appreciated :)
Minty
 
Posts: 5
Joined: Wed May 14, 2008 12:39 pm

Postby richardk » Sun Jul 13, 2008 10:39 am

With no mod_rewrite, do you see the same page when you go to example.com and sub.example.com?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Add missing trailing slashes.
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteRule ^(.*)$ /sub/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 22 guests

cron