5

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]
3
  • "Kept the same filenames." - So your PHP files are actually "filename.asp"? Commented Nov 25, 2012 at 0:02
  • @w3d That's obviously not what he meant. Same file name, new extension. Commented Nov 25, 2012 at 7:14
  • Sorry for the late reply. Yes, I kept the filenames but changed the extensions. Commented Nov 26, 2012 at 16:16

4 Answers 4

5

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

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

Try

RewriteEngine on
RewriteRule ^(.*)\.php$ $1.asp [nc]
5
  • Thanks for the reply. Hmmm... that actually didn't do anything. It isn't redirecting at all. Commented Nov 23, 2012 at 21:59
  • What web server are you using? Commented 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! Commented Nov 26, 2012 at 16:25
  • @PaulHanak is there any other rewrites in your .htaccess would you please paste the entire file if so. Commented 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. Commented Nov 26, 2012 at 17:43
0

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
  • 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) Commented Nov 27, 2012 at 0:27
-1

try

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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.