• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

.htaccess redirect

asuh

Golden Member
Here's what I want to do.

I want to turn http://www.mywebsite.com/folder/subdomain/index.html into http://subdomain.mywebsite.com.

So, basically this means there's a folder in a subdirectory of my root that I want to use as a root for a subdomain. So let me use a real website just to be very clear.

http://www.microsoft.com/windows/longhorn/index.html
http://longhorn.windows.com

I want the second, not the first to show up in the address bar. My host uses cpanel for the administration and I can easily add a subdomain like longhorn.windows.com. And, when I try to point my browser in that direction by typing it into the address bar, it loads the site and the address bar then appears similar to www.microsoft.com/windows/longhorn.

When I create a subdomain from cpanel, it then creates a folder off of the root public_html. So, for example, let's say I create longhorn.microsoft.com. It will then create a folder called longhorn that you can see from the root of my domain. Must this folder absolutely exist? Because, I want to redirect the domain longhorn.microsoft.com to another folder located here public_html/windows/longhorn/. This being said, it'd seem redundant to have two folders called longhorn and only one of them to be used.

I know this requires some kind of .htaccess lines but I'm not sure how to do it. As well, when I do create the file with the correct code, where does the file need to be? In the public_html directory or the actual subdirectory?

Any answers would be veeeerrrrrrryy appreciated!!
 
it'd be easiest to ask your webhost to change your doc root for subdomain.yoursite.com to public_html/subdomain
 
You could also just create a symlink between the two folders...but I dont see why you need the content to be in another sub directory.
 
The reason I want the content to be another sub directory is because I'm a web designer. Say, for instance, I am working with a client from Intel. So, I have a sub directory setup that can be accessed like www.mydomain.com/webdesign/intel. I would like for anyone at Intel who needs to see my design in progress to see intel.mydomain.com instead of the previous. It just looks more professional that way. I also can keep all of my web designs in one folder called webdesign.

MCrusty: What is a symlink?

jfall: I'm not sure how to ask my webhost about the doc root. I'm not even sure what that is.
 
By doc root I mean document root, it's where Apache looks for files relating to your subdomain. You just need to have your webhost point it to the location of your files
 
So jfall, if I decide to use a lot of subdomains, won't they have to do this for every subdomain I create? That sounds more like a hassle, especially if lots and lots of people are doing that all the time.
 
If you have ssh access to your webserver you would create a symlink like follows.

ln -s public_html/windows/longhorn/ public_html/longhorn

So whenever somebody accesses public_html/longhorn they are in fact accessing public_html/windows/longhorn

That way, nobody needs to mess with the doc root, and cPanel works with the default settings.
 
unfortunately, I do not have ssh access. They won't allow it for some reason, though I can't remember why.
 
So jfall, if I decide to use a lot of subdomains, won't they have to do this for every subdomain I create? That sounds more like a hassle, especially if lots and lots of people are doing that all the time.

Well for blah.somedomain.com to work at all it would need a valid DNS entry and a VirtualHost entry in Apache, not exactly things you can do with a .htaccess file.
 
Okay, this is messed up. I contacted my webhost about this subdomain mess and they told me one of two things. I could either use an .htaccess file or open up another whole account in the name of the subdomain. The second option seems crazy, but the first one seems logical. I can't believe they wouldn't give me more help, but for whatever reason they won't. So, it's gotta be possible or I'm gonna be lost!
 
It shouldn't be that difficult...as far as I know, you just have to set up the root directory to be where the index file is, create the subdomain, and that should be it...it may take a few days for the DNS servers to role over though.
 
Is there an easy way to do this using cpanel? I don't understand why this is so complicated. Shouldn't I just be able to create a subdomain in cpanel with it automatically using the subdomain address in the address bar instead of pointing to the actual location?

I looked at that apache link and it's too technical for me. Where do you change the setup in the core server configuration?

Just as well, if I have to point some DNS servers, how would I do that locally through my cpanel? Or is this on the server administration side?
 
why won't something like this work?

RewriteEngine on

RewriteCond %{HTTP_HOST} ^subdomain.website.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain.website.com$
RewriteRule ^(.*)$ http://website.com/subdomain/$1 [R=301,L]

I tried this in a .htaccess file but it didn't work.
 
You still need an Apache VirtualHost definition for it to recognize the domain, otherwise it will probably fall back on the default VirtualHost which is most likely your provider's web page.
 
so basically, unless I get access to my Apache server, I'm pretty much gonna have to live with what I have? I find that frustrating! What's the point of a subdomain if it won't keep the display of the subdomain in the address bar? I think it's so much more professional to be able to do that.
 
What's the point of a subdomain if it won't keep the display of the subdomain in the address bar? I think it's so much more professional to be able to do that.

A subdomain has a lot more uses than just web space. And Apache will leave the name of the subdomain in the address bar, but you have to be able to properly configure Apache to handle that VirtualHost properly.
 
Hey Nothinman, it turns out you were exactly right on what you were saying, but I didn't completely understand why until someone else answered the question on another forum. Here's a link to what I discovered, posted here in case anyone else has the same trouble or questions.

.htaccess and subdomains
 
Back
Top