Forum Moderators: phranque

Message Too Old, No Replies

Help me, virtual subdomain and directory

         

114v

11:02 pm on Dec 11, 2006 (gmt 0)

10+ Year Member



I need virtual subdomain or directory:

[aaa.domainname.com...] => access to user.php?id=aaa
OR
[domainname.com...] => access to user.php?id=bbb

It like multi blog system

Thanks :)

MichaelBluejay

9:54 am on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi, and welcome to WebmasterWorld!

This kind of question is asked a lot so there are articles in the library to help you with this kind of thing. Click the "Library" link right above the title of this forum ("Apache Web Server") and look for the Intros to ModRewrite.

Please make a go of it yourself, and then if your code doesn't work, post it here and someone will help you.

114v

5:37 pm on Dec 12, 2006 (gmt 0)

10+ Year Member



My .htaccess

RewriteEngine On
#http://mydomain.com/a
RewriteRule ^(.*)$ ./u.php?id=$1 [L]

#http://b.mydomain.com
RewriteCond %{HTTP_HOST} www\.mydomain.com [NC]
RewriteCond %{REQUEST_URI}!\. [NC]
RewriteRule ^(.+)$ u.php?id=$1 [L]

u.php

if ($_GET[id] == 'a') {
echo "aaaaaaaaaaaaaaaaaaaaaa";
} elseif($_GET[id] == 'b') {
echo "bbbbbbbbbbbbbbbbbbbbbb";
} else {
echo "OOP!";
}

I try: [mydomain.com...] => error: 500 Internal Server Error

and: [a.mydomain.com...] => error: The page cannot be displayed

equalm

6:37 pm on Dec 12, 2006 (gmt 0)

10+ Year Member




114v,

1) Are aaa.domainname.com and domainname.com aliases of the same Virtualhost?

2) You have a lot of global writing going on, one red flag I see is this

RewriteRule ^(.*)$ ./u.php?id=$1 [L]

Personally, to make things safe, I wouldn't add a ./u.php but i'd just do a absolute path to /u.php

Also, add a / to your original pattern, otherwse, the $1 might be a value of "/aaa" Not totally sure about that one.

^/(.*)$

but it's always preferable to narrow down your regex pattern. .* is a very dangerous pattern to match. Can't you do ([a-zA-Z0-9]+)?

.

114v

11:12 pm on Dec 12, 2006 (gmt 0)

10+ Year Member



Thanks :)

I'm using shared host. I havent Virtual host.

I fix to:

RewriteRule ^/([a-zA-Z0-9]+)$ u.php?id=$1 [L]

but: HTTP 404 Not found :( (http://mydomain.com/b)

equalm

7:16 am on Dec 13, 2006 (gmt 0)

10+ Year Member




Hmmm, shared hosting means very little logging (ie. rewrite logging) Any chance you can look at the error log? Do the 404 errors show up there?

I think you need to get a little more specific in your example. Don't use the domain you use, but would you use the actual keywords/subdomains you're using? You have given too little data to work with, which is probably why most people haven't chimed in.

.

equalm

7:18 am on Dec 13, 2006 (gmt 0)

10+ Year Member




<quote>
RewriteRule ^/([a-zA-Z0-9]+)$ u.php?id=$1 [L]
</quote>

Also, the rewrite rule you should use, if the inbound link is indeed:

[domain.com...]

RewriteRule ^/([a-zA-Z0-9]+) /u.php?id=$1 [L]

I don't know if you have /aaa with other trailing query strings or not, so I left out the "$"

.

equalm

7:19 am on Dec 13, 2006 (gmt 0)

10+ Year Member




BTW, if anybody is reading this, would someone tell me how to quote something in those gray dialog boxes? I haven't learned the proper tags to use yet when replying to posts.

MichaelBluejay

7:31 am on Dec 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Put what you want between quote tags: <quote></quote>, except use brackets [] instead of <>. I can't type the syntax with brackets otherwise it will get put in a little gray box. But that did help me discover a neat little trick:

phranque

9:03 am on Dec 13, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



but you can only quote to 13 levels (un?)fortunately.
not that i tested it...

phranque

9:06 am on Dec 13, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



oh and i forgot to mention, equalm, the markup/style codes are here:
[webmasterworld.com...]
a link to which is found to the left of the Message Body edit textarea on the Compose Reply Message page.

114v

10:12 am on Dec 13, 2006 (gmt 0)

10+ Year Member



No no, please... Digress already!

How to make: [[b]a[...]

Thanks :)

114v

10:18 am on Dec 13, 2006 (gmt 0)

10+ Year Member



OH!

Error BBCode..........

How to make: a.mydomain.com thanks :)

equalm

12:14 am on Dec 14, 2006 (gmt 0)

10+ Year Member






but you can only quote to 13 levels (un?)fortunately.
not that i tested it...

Well, let's see if this works...

equalm

12:15 am on Dec 14, 2006 (gmt 0)

10+ Year Member




Cool.

114v, did you try the RewriteRule from above? How did it work?

jdMorgan

12:36 am on Dec 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since it was mentioned that the code is in 114v's .htaccess file, the RewriteRule pattern needs to be modified to work there:

RewriteRule ^([A-Z0-9]+)$ /u.php?id=$1 [NC,L]

[No leading slash in .htaccess patterns, note use of pattern end-anchor ($) and NC (No Case) flag]

Jim

[edited by: jdMorgan at 12:39 am (utc) on Dec. 14, 2006]

114v

3:50 pm on Dec 15, 2006 (gmt 0)

10+ Year Member



Im using this htaccess:

RewriteEngine On
Options +Followsymlinks
RewriteBase /

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^/]+)/?$ /u.php?id=$1 [L,NS]

Work well

Code:
RewriteRule ^([A-Z0-9]+)$ /u.php?id=$1 [NC,L]

Thanks much, very good, but it cannot access to example_dir or images directory:

- public_html
¦- example_dir
¦- images

jdMorgan

4:14 pm on Dec 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That solution is OK, except that it has to check the filesystem twice for each and every HTTP request. This can lead to a slow server if you have a lot of visitors.

Another way to avoid rewriting your /example and /image directory requests is to exclude them explicitly:


RewriteCond $1 !^(example_dir¦images)/
RewriteRule ^([A-Z0-9]+)$ /u.php?id=$1 [NC,L]

This avoids having to check each request for "file exists" and "directory exists".

Replace the broken pipe "¦" character in the code above with a solid pipe character before use; Posting on this forum modifies the pipe character.

You can do it either way, but it's best to avoid slow functions such as reverse-DNS lookups and filesystem checking whenever possible.

Jim

114v

12:07 am on Dec 16, 2006 (gmt 0)

10+ Year Member



Yes, it very slow

Thanks jdMorgan :)