htaccess and spinning

I simply designed a subdomain on my small webside mainly becouse i would like a spesific address into it.

Allows say this site is : http://website.com And my subdomain is http://sub.website.com using its primary folder in /home/username/public_html/sub/

After i go into the subdomain address the address suddently changes to http//website.com/sub/

how do i keep your subdomain address?

EDIT for Dennis:

i've got a rule that directs all http://www.website.com to http://website.com

I personally use

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


even when i comment out this the address still changes to

http://website.com/sub/


Better of regards, Alexander

I'd imagine something similar to this could work (not examined):

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: based on the documentation, Options FollowSymLinks must be a choice you are able to override to obtain the rewrite to operate.

The very first RewriteCond will make sure the "webiste.com" host isn't rewritten (but domain names like sub.website.com will). The 2nd one matches anything as much as the very first us dot from the hostname. These two must succeed and when therefore the host part is obtainable in %1.

The very first RewriteRule rewrites the args towards the php script towards the directory pathways (a big change seen on URL around the browser). The following RewriteRule uses the [P] flag to proxy any demands from the form /xx/yy/ to %1.php (our appreciated host title) using the args passed towards the php script.

As I have mentioned, this isn't examined, but hopefully it'll enable you to get "within the right direction".

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

Another option would be to possess a Virtualhost devoted for the subdomain (which should already be, otherwise you will get lots of problems) and also to get this to VirtualHost ignore .htaccess instructions from the master domain. You need to really keep your subdomain configuration independant from the master domain domain configuration.

Let us say your documentRoot within the subdomain VH is /home/username/public_html/sub/, when Apache serve the index.php or index.html file or other things within this directoy it works a recursive search of .htaccess in /home/username/public_html/sub/, /home/username/public_html/, /home/username/, /home/ and /. Therefore the rules defined inside your master domain (I believe it's in /home/username/public_html/) are applied.

You are able to tell this subdomain VirtualHost to disregard all .htaccess files that are prior to the VH DocumentRoot with the addition of:

<Directory />
AllowOverride None
</Directory>
<Directory /home/username/public_html/sub/>
AllowOverride All
</Directory>


You can even take away the AllowOverride All, remove all .htaccess and set what you have within the .htaccess of the subdomain (for those who have one) directly within the <Directory /home/username/public_html/sub/> section, same effect without getting Apache trying to find configuration parts around the filesystem (so faster).