Forum Moderators: phranque

Message Too Old, No Replies

.htredirect on subdomain

how to get .htaccess to work on subdomains

         

Deccypher

11:26 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



Hi All,

i have been using this .htaccess for moving subdomain request to a index.php variable

wanted results

http://sometext.example.com
parses out to
http://example.com/file.php?domain=sometext

this is the .htaccess code I'm using to achieve this

Options +FollowSymLinks
rewriteEngine on
rewriteCond %{HTTP_HOST}!^(www\.)?example\.com [NC]
rewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC]
rewriteRule .* /clientindex.php?username=%1 [L]

i will admit to using a plesk back end witch makes its own sub domain folder which starts outside the normal httpd folder but this rewrite should take care of that (i have me DNS Set to *.example.com -->example.com)

any help in identifying what it is i missed would be a great help

[edited by: Deccypher at 11:53 pm (utc) on Oct. 27, 2008]

jdMorgan

11:52 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I see:

  • Missing a space between "}" and "!".
  • Nothing in the code to stop a request for clientindex.php?username=abc from being rewritten to itself in an 'infinite' loop.

    You say "I have been using," so it's not clear: Does this code work or not? If so, what is the question? And if not, then what is the problem? -- What are the results you get, and how do they differ from what you want and expect?

    Jim

  • Deccypher

    12:11 am on Oct 28, 2008 (gmt 0)

    10+ Year Member



    Hi The code works on a cpanel hosted site but not on this new plesk hosted site. i'm trying the addition of the space now ill update in a few.

    Deccypher

    12:28 am on Oct 28, 2008 (gmt 0)

    10+ Year Member



    Hi i made 2 aditions and got it to work

    Thanks jdMorgan there was a space issue between "}" and "!". also the was an issue due to not using the full url so the working code is now

    rewriteEngine on
    rewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
    rewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC]
    rewriteRule .* http://example.com/clientindex.php?username=%1 [L]

    g1smd

    12:30 am on Oct 28, 2008 (gmt 0)

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



    What happens if someone requests www.username.example.com?