Apply mod_rewrite rule to all domains without editing every VirtualHost

Discussion in 'Apache' started by Piranha, Mar 23, 2009.

  1. #1
    I have a large number of domain names hosted on a server. I'd like to apply the same mod_rewrite rule to all of them. Is this possible without edititing every <virtualhost>.

    The reson I'm doing this is I want ever www version of a domain (www.example.com) to redirecto the non-www version (example.com). I already have the rule and it works fine if I put it inside the <virtualhost> but I'd like to apply it to all domains without editing 100+ virtualhosts.

    If I do have to edit all the virtualhosts what can I do to prevent this happening in the future?
     
    Piranha, Mar 23, 2009 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    You did NOT give exact details on OS or server
    assuming you have Linux and apache 2.2

    there are several "layers" of configuration
    on my opensuse apache for example
    there would be a
    httpd.conf
    or even a more detailed
    default_server.conf

    that would be suitable for what you are looking for = to add system wide configuration for all domains / entire server wide

    just make sure you later on do NOT exclude / de-activate /override some of these system wide server rules.

    needless to say that you then FIRST check your server config BEFORE rebooting apache !! and before your daily log file rotation runs
    else you may have a downed server if any error in syntax exist.
    all rules are activated by apache restart - or by log file rotation ( which usually does an apache reload )

    hence a good idea is to test your / any rules on a single domain or folder in .htaccess
    then implement it system wide
     
    hans, Mar 26, 2009 IP