htaccess redirect with or without www to static page

Posted on 2011-04-20
Last Modified: 2012-05-11
I need to redirect a new domain to a static page within an existing domain.  Here is the code I am using right now that appears to work ok:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*) [R=301,L]

Open in new window

I would like to change this code so it will work with or without the www before
Question by:wardjame
    LVL 31

    Accepted Solution

    You should modify RewriteCond.
    RewriteCond %{HTTP_HOST}

    Does that work for you?

    Author Comment

    Won't that mean it will only work without www and not with?  I need both to work.
    LVL 31

    Expert Comment

    I don't have system to test it right now.  I have removed ^ as well.  It should work with both.  Otherwise, you can get rid of the RewriteCond completely.  That would do it.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now