Forum Moderators: phranque

Message Too Old, No Replies

Redirection from subdomain to domain

redirectionn from subdomain to domain not working

         

abhichak

12:24 pm on May 4, 2010 (gmt 0)

10+ Year Member



Hi

I am a new person into .htaccess programming. Just created my first script but its not working. Please check it and tell me what is wrong. What i needed to do was person will register on my site he will get a url. http://user.example.com/. On accessing it will redirect to http://www.example.com/show.php?username=user. Seeing earlier threads i created the following code but its not working.

RewriteEngine On

# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]

# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail)$ [NC]

# Redirect all requests to a php script passing as argument the subdomain
RewriteRule ^.*$ http://www.example.com/show.php?username=%1 [R,L]


Please help me and tell me what is wrong

Thanx in advance
Abhishek Chakravarty

[edited by: jdMorgan at 3:12 pm (utc) on May 4, 2010]
[edit reason] Please use example.,com. See TOS and Charter. [/edit]

jdMorgan

3:26 pm on May 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> but its not working.

Given only that information, the only answer we could possibly give about the cause would be "because it is broken" -- not very useful.

Please tell us how, specifically, it does not work:
o How did you test -- what address did you type?
o What error messages do you see?
o What is in your server error log when you get the error?

Taking a few guesses, I'll ask:

Do you have any other working rewriterules?

Did you configure the DNS for your domain to map all possible subdomains to your server's unique IP address?


And regarding intended function, what will you do with a request for "jdMorgan.example.com/jims-page.html"? As your code is written now, the name of the "page" I asked for will be discarded. Not only might this offend user jdMorgan, but it also creates a duplicate-content problem, because username.example.com/<anything-at-all-here> will always produce the same HTML-content page.

Also, are you sure you really want an external redirect instead of an internal rewrite? As written, your code will expose "http://www.example.com/show.php?username=jdMorgan" as a URL, and it will be indexed by search engines and shown in search results. Using an internal rewrite, the originally-requested "http://jdMorgan.example.com/jims-page.html" would be indexed and listed, and this is what 99% of all Webmasters would want to do....

If you do want a redirect, I'd suggest it should be a 301-Moved Permanently, unless you plan to add and remove all "users" on a weekly or daily basis.

Jim