I just made a subdomain on my webside mainly becouse i want a spesific address to it.

Lets say my website is : http://website.com And my subdomain is http://sub.website.com with its main folder in /home/username/public_html/sub/

When i enter the subdomain address the address suddently changes to http//website.com/sub/

how can i keep the subdomain address?

EDIT for Dennis:

i have a rule that directs all http://www.website.com to http://website.com

I use

RewriteEngine on
Redirect to non-www
RewriteCond %{HTTP_HOST} !^(website\.com)?$
RewriteRule (.*) http://website.com/$1 [R=301,L]

even if i comment out this the address still changes to

http://website.com/sub/

Best of regards, Alexander

Comments

You can't easily rewrite sub.php?blahblah into a pretty url, because the rewrite rule engine won't match the query string without intensive precondition checking. Doing that at the php level will be simpler.

Written by Denis

ok then. But if i create a subdomain sub.website.com and go to that address, then the address suddently changes to website.com/sub , is it possible to keep the sub.website.com address?

Written by Alexander

maybe you've a script in there that redirects. if not, that would be a question for your host...

Written by Denis

hmm perhaps, i do redirect from www. to non www. check edit

Written by Alexander

Accepted Answer

I would imagine something like this would work (not tested):

Options FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^website\.com
RewriteCond %{HTTP_HOST} ^([^.]+)
RewriteRule \?cat_id=([0-9]+)&photo_id=([0-9]+) http://website.com/$1/$2/
RewriteRule ^/(.*)/(.*)/ /%1.php?cat_id=$1&photo_id=$2 [P]

Note: according to the documentation, Options FollowSymLinks needs to be an option you can override to get the rewrite to work.

The first RewriteCond will ensure the "webiste.com" host is not rewritten (but domains like sub.website.com will). The second one matches anything up to the first dot of the hostname. Both of these must succeed and if so the host part is accessible in %1.

The first RewriteRule rewrites the args to the php script to the directory paths (a change seen on URL on the browser). The next RewriteRule uses the [P] flag to proxy any requests of the form /xx/yy/ to %1.php (our remembered host name) with the args passed to the php script.

As I've stated, this is not tested, but hopefully it will get you "in the right direction".

EDIT: removed the [R] from the first rewrite rule.

Written by Drav Sloan
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki