htaccess redirect

Posted on 2012-09-06
Last Modified: 2012-09-07
Hello all,

Is it possible to create a redirect rule when an url does not contain anything after the domain extension? Because I have a local, production and live version the domain extension should be treated as variable. -- redirect to --> -- redirect to -->
mydomain.local -- redirect to --> mydomain.local/nl -- no redirect
mydomail.local/fr/whatever/comes/next -- no redirect

Can this be done?


Question by:wal_toor
    LVL 9

    Expert Comment

    by:Derek Jensen
    You should be able to accomplish this using a regexp similar to the following:

    Open in new window

    This will match both domains you have listed above; however, I'm sure you'll have to modify it to your needs.
    I'm not sure what the exact syntax of the rule should look like, but I do know that .htaccess supports regexes.
    LVL 26

    Accepted Solution


    RewriteEngine On
    RewriteCond  %{HTTP_HOST}    [OR]
    RewriteCond  %{HTTP_HOST} mydomain.local
    RewriteRule  ^/?$    /nl   [L,R=301]

    Open in new window

    LVL 8

    Author Closing Comment

    Spot on!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 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

    19 Experts available now in Live!

    Get 1:1 Help Now