.htaccess mod_rewrite - send all 404 to PHP script aling with full query string

Posted on 2008-11-12
Last Modified: 2012-05-05
I need a rewrite rule to take all unknown directory/file requests that have no match and point them to a specific url, along with the full query string of the original request

so I need this:
to point to:

And I need this:
to point to:

I know this is wrong, but I think I am going in the right direction:
Options +FollowSymlinks
RewriteEngine      On
RewriteCond            %{REQUEST_FILENAME} !-f
RewriteCond            %{REQUEST_FILENAME} !-d
RewriteRule            ^(*)$ /index.php?action=oldLinkConversion&queryString=$1

Question by:trickyidiot
    LVL 27

    Accepted Solution

    Yes, very close. A period '.' (=1 or n characters) was/is missing in your rule-pattern:
    Options +FollowSymlinks
    RewriteEngine      On
    RewriteCond            %{REQUEST_FILENAME} !-f
    RewriteCond            %{REQUEST_FILENAME} !-d
    RewriteRule            ^(.*)$ /index.php?action=oldLinkConversion&queryString=$1 [QSA,L]

    Open in new window

    LVL 27

    Expert Comment

    to be more correct:
    .  stands for [one] any character
    and .* makes it to 1 or n of "any characters"
    LVL 6

    Author Closing Comment

    Perfect - Thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    A Change in PHP Behavior with Session Write Short Circuit ( (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
    If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now