• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • Support for BIND DNS has been removed from Plesk for Windows due to security and maintenance risks.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS.

ReWrite rule

C

CBiLL

Guest
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
 
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.
 
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
 
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)
 
Originally posted by jamesyeeoc
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)



yeah that did the trick!

Thank you.

Bill
 
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
><>
 
Back
Top