logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: httpd.conf directive for 301 domain.com to www.domain.com
Author
consultant



Joined: 29 Mar 2011
Posts: 4

PostPosted: Mon 11 Jan '16 18:52    Post subject: httpd.conf directive for 301 domain.com to www.domain.com Reply with quote

All my sites domain.com doesn't do a 301 redirect to www.domain.com. Rather than correcting this in the .htaccess file of each site, I'd like to add a directive in the global pre-include file that is included with the httpd.conf file of each site but I'm not an Apache httpd.conf expert (obviously) Can the redirect be setup there and if so what is the syntax? I've googled like crazy and can't find an example.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Wed 13 Jan '16 13:22    Post subject: Reply with quote

force www in a vhost

Code:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Back to top


Reply to topic   Topic: httpd.conf directive for 301 domain.com to www.domain.com View previous topic :: View next topic
Post new topic   Forum Index -> Apache