domain.com/folder to folder.domain.com works 1/2 way

Using a single web hosting account to host multiple sites

domain.com/folder to folder.domain.com works 1/2 way

Postby Deliriumxx » Fri May 12, 2006 8:48 pm

I have an interesting problem...

ona domain name i have a bunch of folders and I am making subdomains out of them...

So what I have is this

www.mydomain.com/somefolder/

and i mod_rewrite to this

somefolder.mydomain.com

To do that I am using this mod_rewrite and it works till that point:

RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com?$
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com?$
RewriteRule ^$ /%1/[L]


However a strange thing happens whan I click on a link on the loaded page. The page doesn't open,,, I get file not found browser error. The I tried accessing the desired file like this

somefolder.mydomain.com/somefolder/somefile.html AND IT WORKED


but I don't want it to work like that... I want this

somefolder.mydomain.com/somefile.html

As a reminder,,, the index file does load on subdomain as long as I am not calling it directly by index.html.

I do realise I am missing somethhing in my mode_rewrite,,, but I am not a savy mod rewrite programmer so I need help.

What am I missing in that mod code?

PLeae help. and THANKS IN ADVANCE!
Deliriumxx
 
Posts: 13
Joined: Fri May 12, 2006 8:34 pm

Postby richardk » Sat May 13, 2006 3:25 am

You're missing appending the REQUEST_URI to the new path.

Code: Select all
RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$    [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule .* /%1%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Deliriumxx » Mon May 15, 2006 8:49 am

It still doesn't work...

I have done this:

Code: Select all
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com?$
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com?$
RewriteRule ^$ /%1%{REQUEST_URI} [QSA,L]


If I put .* into rewrite rule, as you did

Code: Select all
RewriteRule .* /%1%{REQUEST_URI} [QSA,L]


then I get an error.

Do you happen to have a fully working code example that is maybe written diferently from mine?[/code]
Deliriumxx
 
Posts: 13
Joined: Fri May 12, 2006 8:34 pm

Postby richardk » Mon May 15, 2006 9:02 am

Code: Select all
RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$    [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteCond %1---%{REQUEST_URI} !^(.+)---/\1(/.*)?$
RewriteRule .* /%1%{REQUEST_URI} [QSA,L]


If that doesn't work, what version of Apache is it (1.3 or 2)?
Last edited by richardk on Thu Jun 08, 2006 4:44 am, edited 1 time in total.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Deliriumxx » Mon May 15, 2006 10:22 am

The server is Apache version 1.3.34 (Unix)

I tryed the new code you posted and I can't even get the
subdomain to load with it.

I found this code and it does work when I apply it on a
single folder...

Code: Select all
------------------------------------------------
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^mydir(.*)$ http://sub.domain.com$1 [R,L]

RewriteCond %{HTTP_HOST} ^sub.domain.com$
RewriteCond %{REQUEST_URI} !^/mydir
RewriteRule ^(.*)$ mydir/$1 [L]
------------------------------------------------


Now,, to me,, this code does look very well along the line of the
last code you posted,, I mean the second conditions part.

I am not certain how to make the above code work for every/any folder....

Does this help you help me :)


Thank you.
Deliriumxx
 
Posts: 13
Joined: Fri May 12, 2006 8:34 pm

Postby richardk » Mon May 15, 2006 11:14 am

If this doesn't work, i doubt anything will.
Code: Select all
RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} !^(www\.)?DOMAIN$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.DOMAIN$ [NC]
RewriteCond %1---%{REQUEST_URI} !^(.+)---/\1(/.*)?$
RewriteRule .* /%1%{REQUEST_URI} [QSA,L]


If it isn't working, the problem is that Apache 1.3 doesn't understand the \1 backrefrence. (That's why i asked about Apache version). This is needed to stop the an inifinite loop starting.

The only other thing i can think of is if you can use the P (proxy) flag:
Code: Select all
RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} !^(www\.)?DOMAIN$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.DOMAIN$ [NC]
RewriteRule .* http://DOMAIN/%1%{REQUEST_URI} [QSA,P,L]
Last edited by richardk on Thu Jun 08, 2006 4:43 am, edited 1 time in total.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Deliriumxx » Mon May 15, 2006 11:29 am

When I use this code

Code: Select all
RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} !^(www\.)?DOMAIN$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.DOMAIN$ [NC]
RewriteCond %1---%{REQUEST_URI} !^(.+)---/\1(/.*)?$
RewriteRule .* /%1%{REQUEST_URI} [QSA,L]


I end up seeing my www.mydomain.com ... main site homepage...
Deliriumxx
 
Posts: 13
Joined: Fri May 12, 2006 8:34 pm

Postby richardk » Mon May 15, 2006 11:51 am

Well if neither mod_rewrites work, i doubt it'll work at all. The problem is you need to compare the subdomain (eg "richard" from richard.domain.com), to the first directory of the requested uri (eg. "dir" from /dir/file.ext) to stop an inifite loop. This is because after mod_rewrite rewrites richard.domain.com/page.html to /richard/page.php, it goes through mod_rewrite again, and if it isn't stoppped it will match the same rule again and be sent back through mod_rewrite, causing the loop. To do that you need to use a \1 type backrefrence. Unfortunately your version of Apache does not support it, and i know of no other way to make it work.

The point of this line:
Code: Select all
RewriteCond %{REQUEST_URI} !^/mydir

from the code you posted earlier does that (but slightly different because the directory and subdomain are different), but we can't hardcode the subdomain/directory name because it's not constant, so we need a backrefrence.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Deliriumxx » Mon May 15, 2006 12:08 pm

I see,,, well for the moment I can use the alternative and just allow

Code: Select all
http://subfolder.domain.com/subfolder/somepage.html


to happen...

I have found some more mod_rewrites,,, and I will be looking at them too.
If I come arround this i will post the code. (IF beiing the key word,, lol)

Thank you for helping Richard.
I really appreciate any info on this,, since I am kind of new to Mod_rewrite.

Till later.
Deliriumxx
 
Posts: 13
Joined: Fri May 12, 2006 8:34 pm

Postby Deliriumxx » Mon May 15, 2006 9:16 pm

Richard,, Just an extra question when you get to it...

If I had access to <VirtualHost> would this be solvable?

I am not certain for the moment what to do about this. The point of the entire need is to create subdomains on the fly, and in essence it works, except I am being picky and I want it to apear perfect, LOL.

So,, <VirtualHost>,,, do you have any information on how it would be done without using .htaccess at all?
Deliriumxx
 
Posts: 13
Joined: Fri May 12, 2006 8:34 pm

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 100 guests

cron