sahanz
asked on
Apache mod rewrite for subdomains
I can I do mod rewriting to something like this,
http://user.mydomain.com, actual path is, mydomain.com/user.php?id=u ser
The rewriting is like a sub domain.
Is it possible ?
http://user.mydomain.com, actual path is, mydomain.com/user.php?id=u
The rewriting is like a sub domain.
Is it possible ?
Still the same :(
The subdomain I want to still use is HTTPS if it helps.
So all 3 goes to the new domain.
http://something.com
http://www.something.com
https://live.something.com
The subdomain I want to still use is HTTPS if it helps.
So all 3 goes to the new domain.
http://something.com
http://www.something.com
https://live.something.com
ASKER
not working :(
componentslab, have you posted to the wrong thread? This question was opened by sahanz.
sahanz, what URLs are you trying which don't work? The directives I gave will only work for a request for the domain. If you request a file on the domain, then it will not redirect.
ASKER
ummm, I typed the direct URL. www.test.mydomain.com
That doesn't fit the pattern described in your question (that has three subdomains rather than two).
Can you describe a list of all possible types of pattern that need to be matched and redirected, and where they should be rewritten to (and any patterns which must not be redirected)?
Can you describe a list of all possible types of pattern that need to be matched and redirected, and where they should be rewritten to (and any patterns which must not be redirected)?
ASKER
ok its like this, I have a php site and there is a members area. once user log in, site set up a cookie and then user can browse through the site. Lets say the main site domain is www.domain.com and we have 3 pages.
www.domain.com/view.php
www.domain.com/upload.php
www.domain.com/edit.php
So with rewriting what I want is, to make it accessible to these 3 pages, using username as a subdomain.
www.user.domain.com/view.php
www.user.domain.com/upload.php
www.user.domain.com/edit.php
www.domain.com/view.php
www.domain.com/upload.php
www.domain.com/edit.php
So with rewriting what I want is, to make it accessible to these 3 pages, using username as a subdomain.
www.user.domain.com/view.php
www.user.domain.com/upload.php
www.user.domain.com/edit.php
Right, but if someone requests www.user.domain.com/view.php in their browser, what is the path of the actual script you want called? Because you've now got two variables: username and filename. I'm guessing you need it to go to a file something like this:
mydomain.com/user.php?id=u ser&page=v iew.php
But you need to be explicit, because my mind reading ain't so hot.
mydomain.com/user.php?id=u
But you need to be explicit, because my mind reading ain't so hot.
ASKER
yes that correct,
mydomain.com/user.php?id=u ser&page=v iew.php
Sorry for beating around the bush :)
mydomain.com/user.php?id=u
Sorry for beating around the bush :)
In that case, try:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mydomain\.com$
RewriteRule ^([a-z]+\.php)$ http://mydomain.com/user.php?id=%1&page=$1
You may need to tweak the ([a-z]+\.php) pattern if your page names are more complicated than view.php (maybe including hyphens, underscores, etc).
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mydomain\.com$
RewriteRule ^([a-z]+\.php)$ http://mydomain.com/user.php?id=%1&page=$1
You may need to tweak the ([a-z]+\.php) pattern if your page names are more complicated than view.php (maybe including hyphens, underscores, etc).
ASKER
Hi, Seems its not working correctly.
my main domain, is http://tinyurl.com/39olmfw
I have this setupd under the domain, http://tinyurl.com/3y7naf3
so user.mydomain.com would redirect to, mydomain.com/test/user.php ?id=user
my main domain, is http://tinyurl.com/39olmfw
I have this setupd under the domain, http://tinyurl.com/3y7naf3
so user.mydomain.com would redirect to, mydomain.com/test/user.php
ASKER
Do I need to enable something from apache? Wildcard subdomain or something?
it looks like it's possible to use rewriting, but the user will simply be "redirected" and not masked. So the URL will still be ugly. Why exactly do you want this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, seems I need root access.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mydomain\.com$
RewriteRule ^$ http://mydomain.com/user.php?id=%1
This will capture any subdomain other than www and redirect requests to the root page to your user.php script.