1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

ReWrite rule

Discussion in 'Plesk for Linux - 8.x and Older' started by CBiLL, Sep 20, 2005.

  1. CBiLL

    CBiLL Guest

    0
     
    I need to prevent anyone going to my website by using http://domain.com (no www in address) and force thier browser to be redirected to http://www.doman.com (with www in address) because the php script I use have cookie issue and remembering visitor unless they use the www in thier address.

    So I tried adding perment redirect to the vhost.conf and restarted apache in plesk service but nothing changes you still could access the website by domain.com and not be redirected to the www.domain.com


    Here the rule I tried in vhost.conf to get domain.com redirected to www.domain.com keeping path after it intacted.

    <VirtualHost 00.00.00.00:80>

    RewriteEngine on
    RewriteRule ^/(.*) http://www.domain.com/$1 [R]

    </VirtualHost>



    Am I doing something wrong? or is there another method to do this?


    Thanks
    Bill
     
  2. jamesyeeoc

    jamesyeeoc Guest

    0
     
    I thought that since there was already a VirtualHost section in the httpd.include file that you could not have a duplicate in the vhost.conf file....

    What you have written will be applied to all, not just the ones who don't have the www.

    I would put a RewriteCond to match just those who do not have the www
    Code:
    [b]
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteMap      lowercase       int:tolower
    RewriteCond   %{HTTP_HOST}   !^[url]www.domain.com[/url]$
    RewriteCond   %{HTTP_HOST} ^domain.com$
    RewriteRule   ^/(.*)   [url]http://www.domain.com/[/url]$1 [R=301,L]
    </IfModule>
    [/b]
    1. Turn engine on
    2. Make sure it's not already www.domain.com (not absolutely needed, but what the heck)
    3. Make sure it's just 'domain.com' not something else (another subdomain?)
    4. Redirect to the www.domain.com with any additional dirs requested ($1)
    5. No <VirtualHost xxx> statements
    6. This goes in the
    /home/httpd/vhosts/domain.com/conf/vhost.conf
    file.
    [Edit: forgot to remind to run the following after making changes:]
    Code:
    /usr/local/psa/admin/bin/websrvmng -u --vhost-name=domain.com
    
    Then restart Apache after this.
     
  3. CBiLL

    CBiLL Guest

    0
     
    this is what I have in my vhost.conf


    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteMap      lowercase       int:tolower
    RewriteCond   %{HTTP_HOST}   !^[url]www.findmall.com[/url]$
    RewriteCond   %{HTTP_HOST} ^findmall.com$
    RewriteRule   ^/(.*)   [url]http://www.findmall.com/[/url]$1 [R=301,L]
    </IfModule>
    
    then I restarted apache.


    and going to http://findmall.com does not rewrite to http://www.findmall.com

    Am I missing something here or doing something wrong?


    Thanks
    Bill
     
  4. jamesyeeoc

    jamesyeeoc Guest

    0
     
    After you made the changes, did you run:

    /usr/local/psa/admin/bin/websrvmng -u --vhost-name=findmall.com

    Then restart apache after this.

    (sorry I forgot to remind about that in my original post, now edited)
     
  5. CBiLL

    CBiLL Guest

    0
     


    yeah that did the trick!

    Thank you.

    Bill
     
  6. fishnyc22

    fishnyc22 Guest

    0
     
    Hey Guys. This worked great for me as well. One question. How can I get this to work for my https:// domain as well?

    Thanks

    Fish
    ><>
     
  7. thewolf

    thewolf Regular Pleskian

    25
    57%
    Joined:
    Mar 11, 2004
    Messages:
    231
    Likes Received:
    0
    I'm interested into this as well, does anyone know the better way to do that?

    Thanks.
     
Loading...