Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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

3 Answers 3

up vote 2 down vote accepted

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

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

Try

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

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.

share|improve this answer
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 '12 at 0:27
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.