Ahoy all! I've been racking my brain with this one.

I basically just converted all of my pages from ASP code to PHP code. Kept the same filenames.

So, here is the htaccess code I have so far, but it keeps redirecting to my ROOT.... ie /home/accountname/publc_html...

What am I doing wrong?

RewriteRule (.*)\.asp $1.php [R=301]
  • "Kept the same filenames." - So your PHP files are actually "filename.asp"?
    – MrWhite
    Nov 25, 2012 at 0:02
  • @w3d That's obviously not what he meant. Same file name, new extension.
    – Kenzo
    Nov 25, 2012 at 7:14
  • Sorry for the late reply. Yes, I kept the filenames but changed the extensions.
    – PaulHanak
    Nov 26, 2012 at 16:16

4 Answers 4


try adding a slash before the target url ($1) like:

RewriteEngine on
RewriteRule ^(.*)\.asp$ /$1.php [R=301,NC]
  • Well, this was it, except backward!! RewriteRule ^(.*)\.asp$ /$1.php [R=301]
    – PaulHanak
    Dec 3, 2012 at 18:40
  • hah thanks for pointing that out, not sure how I missed that one. I'll edit the answer
    – WebChemist
    Dec 3, 2012 at 18:48


RewriteEngine on
RewriteRule ^(.*)\.php$ $1.asp [nc]
  • Thanks for the reply. Hmmm... that actually didn't do anything. It isn't redirecting at all.
    – PaulHanak
    Nov 23, 2012 at 21:59
  • What web server are you using?
    – Anagio
    Nov 24, 2012 at 0:07
  • Sorry for the late reply. Appreciate the help! Linux. I tried with both the NC and the R=301. With the 301, it seems to redirect to the ROOT. For example, it will redirect from sitename.com/name.asp to sitename.com/home/accountname/name.php. Weird!
    – PaulHanak
    Nov 26, 2012 at 16:25
  • @PaulHanak is there any other rewrites in your .htaccess would you please paste the entire file if so.
    – Anagio
    Nov 26, 2012 at 16:44
  • Thank you for the follow-up. The only other rewrite in the htaccess is for hidding hidden files and directories as per the boiler plate. RewriteCond %{SCRIPT_FILENAME} -d RewriteCond %{SCRIPT_FILENAME} -f RewriteRule "(^|/)\." - [F] I have also placed your code at the very top of my htaccess file if that makes a difference.
    – PaulHanak
    Nov 26, 2012 at 17:43

If you are running PHP on IIS and know that you don't have any .asp pages left over you can add a handler for IIS to interpret .asp pages as PHP. This is just a neat trick that masks the fact that you are actually running PHP.

@anagio's rewrite rule will work. Make sure its a permanent redirect by adding the appropriate header.

  • 1
    in Apache you can make .asp work as .php with an AddHandler rule like AddHandler application/x-httpd-php .php .asp (or /x-httpd-php5 depending on how the php handler is defined)
    – WebChemist
    Nov 27, 2012 at 0:27


RewriteEngine on
RewriteRule ^(.*)\.asp$ $1.php [nc]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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