301 redirect not working in .htaccess how do I?

Posted on 2011-04-26
Last Modified: 2012-05-11
I am trying to do a redirect in htaccess but the rule is being ignored.
redirect 301 /index.php?pid=12

I know it works bc I have this code and it redirect the domain to www:
RewriteCond %{HTTP_HOST} !^www\.illumitex\.com [NC]
RewriteRule ^(.*)$$1 [R=301,L]

What I am trying to do is force some spacific older pages back to the main index page or just / .

I have also  tried:
rewriterule index.php?pid=165 [R=301,L]
But that is not working either.
What am I doing wrong?

Question by:jbrashear72
    LVL 12

    Expert Comment

    A question mark is a special character that should be escaped:
    LVL 3

    Accepted Solution

    You can't include %{QUERY_STRING} (identified by the question mark) as part of the RedirectRule.
    You'll want to do something like:

    RedirectCond %{QUERY_STRING} ^pid=12$ [NC]
    RedirectRule .* [R=301,L]

    The question mark in the RedirectRule strips the QUERY_STRING from the URL upon redirect.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    759 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

    8 Experts available now in Live!

    Get 1:1 Help Now