Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a site with many incoming links to the old structure (gone for years), with tonnes of URL vars that are no longer relevant, as the database mappings were changed. So, I'd like to redirect:

http://www.mysite.com/oldfile.aspx?p=1&c=2

to:

http://www.mysite.com/newfile.php

without the query string at the end. The actual query string varies - there are hundreds of them, but since they don't match up to a particular case anymore, I want to take people to the new index page for the content they're looking for, so they can find it from there.

I currently use:

RedirectMatch 301 ^/oldfile\.aspx$ /newfile.php

This puts the query back on the end though. Can someone let me know the voodoo recipe I need?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

RewriteEngine on

RewriteRule ^oldfile.aspx*$ /newfile.php? [R]

This will in the end lead to showin newfile.php in url , if you want users to see oldfile.aspx and really hit newfile.php put [L] instead of [R] flag in mod_rewrite rule.

Add the question mark after newfile.php? so old string after ? gets lost.

share|improve this answer
    
Perfect, thanks. I'd actually tried this after reading a similar thread over on stackoverflow, but I had put a leading / in the regex section. Removed that, and we're away! –  Dan Feb 17 '11 at 15:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.