Search code examples
apache.htaccesshttp-status-code-301

How do I use .htaccess to redirect an aspx page to a php page?


I recently moved from a asp.net host to a PHP host. I am trying to setup 301 redirects of my old urls using .htaccess. Here is what I want to accomplish:

old url: http://www.vasanth.in/downloads/download.aspx?file=file.zip
new url: http://www.vasanth.in/downloads/download.php?f=file.zip

I tried the following:

RedirectMatch 301 /downloads/download.aspx\?file=(.*)$ http://www.vasanth.in/downloads/download.php\?f=$1

This does not seem to work? What am I doing wrong?


Solution

  • Use mod_rewrite, something like this:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^file=(.+)$
    RewriteRule ^(.+)\.aspx$ $1.php?f=%1