Jump to content

Dynamic subdomain to a query; getting error 500


Nuggit

Recommended Posts

It was working for a while, but then I tried to get it into a query, and I haven't even been able to take it back the way it was before. Been trying to solve this on and off for the past month. I thought I understood it but I guess I don't.

 

Help/tips would be VERY much appreciated.

 

RewriteCond %{HTTP_HOST} !^(www\.|musicbox\.|ego\.)domain\.nu$ [NC]
# this might not matter
RewriteCond %{HTTP_HOST} !^domain\.nu$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.nu$ [NC]
RewriteRule (.*) /home/www/domain.nu/htdocs/users/index.php?u=$1 [L]

 

So pretty much, what I'm trying to do, is get it so that if you do

http://username.domain.nu

it leads transparently to

http://domain.nu/users/index.php?u=username

Link to comment
Share on other sites

You might have to be a bit more specific about what you want. I suspect that rather than transparency you actually want this non-transparent to the calling client

 

For a *transparent* (not visible to the user) redirect why not simply redirect the username-controlled virtual host reference directly to the user's folder? What you appear to have rewritten is a call to a local physical folder but with a parameterised index.php which, itself need to call a redirect to "call-back" and be decoded to find the users' home directory. (If I read your intent right from the code). However a) this would require a HTTP:// redirect rather than local folder and b) require an [L,R]. Not sure what you intended here.

 

Maybe something like - RewriteRule (.*) /home/www/domain.nu/htdocs/users/%2/ [L]  ???

Where the RewriteCond backref is inserted (%2) to find the correct user folder and simply pick up any index.htm??

 

You might also re structure RewriteCond %{HTTP_HOST} !^(www|musicbox|ego)\.domain\.nu$ [NC] since all 3 cases *must not* match www.domain.nu, musicbox.domain.nu and ego.domain.nu only - you don't care about isolating the \. from domain.nu in this case.

 

The 4th case you omit is simply domain.nu but, again, you could modify the above to incorporate this case.

Perhaps - RewriteCond %{HTTP_HOST} !^(www\.|musicbox\.|ego\.)?domain\.nu$ [NC] (0 or more matches - ?)

I think that's right - check the inverted logic holds - it's nearly 3am here lol!.

 

 

Link to comment
Share on other sites

What the.

 

It works, if I use %2 instead of $1. How did you do that?! Wow, I need to study more.

 

I really appreciate your tips.

I did mean transparent though, like I want it to stay looking like username.domain.nu, and the $u variable makes everything in index.php work (pulling stuff out of MySQL tables, I mean). The users don't have individual folders. They all use the same PHP files.

But then there's a complication when it goes to a different page, like manage.php... because that needs a "?u=username" as well. username.domain.nu/manage.php?u=username just wouldn't work. I guess what I really want to do is have two rewrite "variables", one for the username and one for whatever PHP page it's on, so that it's not always going to index.php.

 

What you suggested in the last paragraph made a lot of sense. I'm totally using that! :)

Link to comment
Share on other sites

  • 2 weeks later...

So now I'm using this:

RewriteCond %{HTTP_HOST} !^(www\.|musicbox\.|ego\.)?domain\.nu$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.nu$ [NC]
RewriteRule (.*) /home/www/domain.nu/htdocs/users/$1?u=%1 [L]

 

The %1 catches the subdomain, and the $1 catches whatever page it's on. Right? Because the (.*) holds whatever's in the URL after the host name?

 

I'm still getting 500 when I try a user subdomain though. ???

Link to comment
Share on other sites

Not getting many responses here.  :-\ Sorry for the triple post, but at least it's spaced out, and I just want to update, in case it'll help someone in the future via Google or something...

 

I figured out how to do it, sort of.

RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.nu$ [NC]
RewriteRule ^b/(.*)$ /users/$1?u=%1

The problem I'm having is, it gives me a 500 error if I use just ^(.*)$ in the second line there. If I put ^/(.*)$ it doesn't match anything, so it loads http://domain.nu, which isn't what I want. So here, I'm stuck having to type in the URL http://username.domain.nu/b/ to load the correct page.

 

It's odd. Anyone have a clue?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.