htaccess for redirection and query strings

Posted on 2011-10-31
Last Modified: 2012-05-12
Hi there,
I'm trying to use htaccess, but I'm having problems trying to accomplish 3 tasks simultaneously.

1. Redirect to

2. Use clean URLs so that
points at

3. Add exception(s) so that
DOES NOT point at

I appreciate your help. Thanks
Question by:skylabel
    LVL 9

    Expert Comment

    You have specified the requirements, but have failed to mention the issues faced by you.

    Kindly let us know the challenges being faced.

    LVL 1

    Author Comment

    I've got tthe following, but I can't get that exception thing working for

    # AddType application/x-httpd-php .html .php .htm
    AddType php5-cgi htm html
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]
     RewriteRule ^(.*)$$1 [L,R=301]
    RewriteCond %{HTTP_HOST} ^(www.)?mydomain\.com$ [NC]
    RewriteRule ^(.+)/$$1 [R=301,L]
    RewriteCond %{REQUEST_URI} !^/admin/
    RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?htmlID=$1
    RewriteRule ^([a-zA-Z0-9_-]+)/$ page.php?htmlID=$1

    Open in new window

    LVL 19

    Assisted Solution

    I think your easiest course would be simply to split into two vhosts in your httpd.conf (they can have the same root, it doesn't really matter, but this way you can apply your rewrite rules to each with simplicity).  This should actually do everything you need.

    #In VirtualHost for
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !^/admin/
        RewriteRule ^/samplepage   [L,R]
    #In VirtualHost for
        RewriteEngine On
        # This will redirect to
        # It will preserve args too, so goes to
        RewriteRule ^/(.*)        $1 [L,R]

    Open in new window

    LVL 9

    Accepted Solution


    Please make change the lines 9-11 as below and test. This works fine for me.

    RewriteCond %{REQUEST_URI} !^/?admin//* [NC]
    RewriteRule ^([a-zA-Z0-9_-]+)/?$ page.php?htmlID=$1
    #RewriteRule ^([a-zA-Z0-9_-]+)/$ page.php?htmlID=$1

    Open in new window


    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

    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    Read about why website design really matters in today's demanding market.
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    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

    20 Experts available now in Live!

    Get 1:1 Help Now