1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

301s from .asp to .php (htaccess)

Discussion in 'Apache' started by mark_s, Jan 17, 2008.

  1. #1
    I'm moving a website I work for from a Windows platform to Linux so all the pages ending in .asp will be renamed to .php
    SEMrush
    Is there something I can put in the .htaccess file that means when Google comes to a page ending in .asp, it will then automatically know to look for the same file but ending in .php? The site has 100s of pages hence why I'm looking for such a method.

    Thanks.
     
    mark_s, Jan 17, 2008 IP
    SEMrush
  2. gpearce

    gpearce Active Member

    Messages:
    1,433
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Normally, I think you would use Mod_Rewrite; provided that all your page names have just plaintext in them, no - _ and similar, then this rule will most likely work for you :)
    That should catch any pages in upper or lower case with .asp on the end :)
    I did write about this on my blog, I'm fine-tuning it now, but if you're interested, have a peek here:
    Mod_Rewrite, The Basics

    -G
     
    gpearce, Jan 17, 2008 IP
  3. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot!

    But shouldn't it be a 301? Because Google would actually need to be forwarded to the page with .php at the end as the .asp would no longer exist? It's not just plain text, it will also have PHP includes etc.
     
    mark_s, Jan 17, 2008 IP
  4. ruffnat

    ruffnat Peon

    Messages:
    394
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    good question, I am wondering too, so bump for an answer
     
    ruffnat, Jan 17, 2008 IP
  5. gpearce

    gpearce Active Member

    Messages:
    1,433
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    90
    #5
    Had a quick read-around, and it looks like adding this tag to the end of the line does it; [R=301,L]
    Also, I made a little mistake on my rule, here it is revised.
    That should work, I'll add that to my post on Mod_Rewrite soon :)
     
    gpearce, Jan 17, 2008 IP
    mark_s likes this.
  6. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Nice one! Thanks! :D
     
    mark_s, Jan 17, 2008 IP
  7. gpearce

    gpearce Active Member

    Messages:
    1,433
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    90
    #7
    No problems at all mate :)
    +rep apprecaited but not necessary :p
     
    gpearce, Jan 17, 2008 IP
  8. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Sure, there :)
     
    mark_s, Jan 17, 2008 IP
  9. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #9
    mark_s, Jan 22, 2008 IP
  10. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Please can someone help?
     
    mark_s, Jan 23, 2008 IP
  11. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #11
    This version fixes the directory problem...

    RewriteEngine On
    RewriteRule ^(.*)\.asp$ /$1.php [R=301,L,NC]
     
    mark_s, Jan 28, 2008 IP
    ruffnat likes this.
  12. gpearce

    gpearce Active Member

    Messages:
    1,433
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    90
    #12
    Ah, nice one. Sorry for not coming back to help earlier, although ti looks like you fixed it :p
    I didn't get my normal email alert :(
    lol.
     
    gpearce, Jan 28, 2008 IP
  13. Yankee85

    Yankee85 Peon

    Messages:
    1,072
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Damn, who's switching from ASP to PHP? :D
     
    Yankee85, May 8, 2008 IP
  14. apachehtaccess

    apachehtaccess Guest

    Messages:
    82
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Don't forget the query_strings!
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*)\.asp$ /$1.php [R=301,QSA,L,NC]
    Code (markup):
     
    apachehtaccess, May 9, 2008 IP
  15. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Can you explain what you mean?
     
    mark_s, May 10, 2008 IP
  16. apachehtaccess

    apachehtaccess Guest

    Messages:
    82
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #16
    By adding the QSA you ensure that this.asp?anything gets rewritten to this.php?anything

    Otherwise this.asp?anything would be rewritten to this.php

    :)
     
    apachehtaccess, May 10, 2008 IP
  17. RectangleMan

    RectangleMan Notable Member

    Messages:
    2,825
    Likes Received:
    131
    Best Answers:
    0
    Trophy Points:
    210
    #17
    You could also add asp as a handler for php applications. Might be easier and also screw up hackers thinking you run asp.
     
    RectangleMan, May 10, 2008 IP
  18. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Thanks guys.
     
    mark_s, May 11, 2008 IP