Forum Moderators: phranque
RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?mysite\.com\old_directory [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.mysite\.com\old_directory [NC]
RewriteRule .* [subdomain.mysite.com...] [R=301,L]
I came up with code that should do what I want it to, but it still does nothing. The following code should redirect:
http://example.com/directory
to
http://subdomain.example.com
(and show it as such in the address bar)
what I figured out was:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com\.directory
RewriteRule (.*) http://subdomain.example.com/$1 [R=301,L]
I tried this in the root directory, as well as the example.com/directory. Neither work. I seriously dont get it -- what could I be doing wrong?
[edited by: jdMorgan at 9:31 pm (utc) on May 27, 2005]
[edit reason] Example.com [/edit]
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^directory(.*) http://subdomain.example.com$1 [R=301,L]
What did this for me is first putting a redirect in the old subdirectory, like this:
redirect /dir/index.php [subdomain.example.com...]
then putting the mod_rewrite code in the newly created subdomain to rewrite the URL correctly:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^directory(.*) [subdomain.example.com$1...] [R=301,L]
so then, summarily, the simplest approach to direct visitors from one directory to a new subdomain and have the URL of that subdomain seamlessly rewritten in the address bar is:
1) put in redirect in the old directory's htaccess
[example.com/dir]
2) put in rewrite code in the new subdomain's htaccess [http://subdomain.example.com]
I am trying to have it work too,
with the sample code here around I am always getting errors about not found pages.
What I ask is: should DNS setting for such domain rewriting (directory to subdomain) be changed?
Should I set the DNS so that *.domainname.com will work and point to domainname.com?
Or is apache configuration the only thing to be set?
Actually my domain DNS is set to work with [domain.com...] and [domain.com...]
What I would like to get is:
[domain.com...]
to:
[user.domain.com...]
thanks
Yes, you will need to set up "wild card" DNS.
> Should I set the DNS so that *.domainname.com will work and point to domainname.com?
No, set it up so that "*.domainname.com." will point to the same IP address as domainname.com.
After the new DNS settings propagate (4 to 48 hours), you should be able to access "<anything>.domainname.com" and then you can work on rewriting subdomain requests to subdirectories.
Jim
About DNS, I am going to use a virtual host, so the same IP is used for many domains names, and the one I would like to rewrite is not the one who is showed when you use IP.
Are these DNS setting correct?
domain.com. IN A 1.1.1.1 ; Nohost
www IN A 1.1.1.1
* IN A 1.1.1.1 ; catchall
(1.1.1.1 is the shared IP used for this virtualhost)
Thanks a lot!