Apache rewriteCond and Rules for Different domain and different path

Discussion in 'Apache' started by paulmathew, Nov 29, 2008.

  1. #1
    Hi,

    I need an help to write the apache rewriteCond and Rules ...

    Here is the request. I have 2 sub-domain and each domain has different URL format but the content seems to be same. So i want have one code base with main domain and server the details to all the subdomain based on request.

    e.g:
    1. http://subdomain1.mysite.com/user/paul
    2. http://subdomain2.mysite.com/profile/paul

    both these pages are equal to http://mysite.com/paul

    So i want write the rewrite Condition in mysite.com something like below ..

    RewriteCond %{HTTP_HOST} ^subdomain1.mysite.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/user/*$
    RewriteRule ^/user/(.*)$ /home/$1

    RewriteCond %{HTTP_HOST} ^subdomain2.mysite.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/profile/*$
    RewriteRule ^/profile/(.*)$ /home/$1

    also if someone type just subdomain1.mysite.com/user or subdomain1.mysite.com/user/ i want to show some default profile page as mysite.com/defaultuser which i am ready to hardcode in rule.

    since i am new to apache rewrite could someone help me ....

    Below is the complete URL mapping rules.

    1. http://subdomain1.mysite.com/user --> mysite.com/<subdomain>
    2. http://subdomain1.mysite.com/user/ --> mysite.com/<subdomain>
    3. http://subdomain1.mysite.com/user/(*) --> mysite.com/(*)
    4. http://subdomain2.mysite.com/profile --> mysite.com/<subdomain>
    5. http://subdomain2.mysite.com/profile/ --> mysite.com/<subdomain>
    6. http://subdomain2.mysite.com/profile/(*) --> mysite.com/(*)
    7. http://subdomain1.mysite.com/user/detail/(*)/(*) --> mysite.com/detail/$1/$2

    Thanks in advance,
    Paul.
     
    paulmathew, Nov 29, 2008 IP