Forum Moderators: phranque
[aaa.domainname.com...] => access to user.php?id=aaa
OR
[domainname.com...] => access to user.php?id=bbb
It like multi blog system
Thanks :)
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.
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
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]+)?
.
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.
.
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 "$"
.
RewriteRule ^([A-Z0-9]+)$ /u.php?id=$1 [NC,L]
Jim
[edited by: jdMorgan at 12:39 am (utc) on Dec. 14, 2006]
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
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]
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