.htaccess how to rewrite .php pages to .htm pages

Discussion in 'Apache' started by justinlorder, Feb 22, 2009.

  1. #1
    Hello, buddies .

    Question 1:
    As the title above
    How can I rewrite .php pages to .htm pages.
    How can I rewrite .php pages to .html pages.
    (Other requirement:after rewriting, visitors can't visit original php pages or 404 error if visitors try to visit the original php page.)

    Question 2:
    If there is following code in index.php
    <?php
    require_once('foot.php' );
    ?>
    After rewrite, do I have to change the code to
    <?php
    require_once('foot.html' );
    ?>

    I am a newbie in .htaccess rules .
    Thanks for your help.
     
    justinlorder, Feb 22, 2009 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    You can rename all your .php to .html and/or .htm then add the appropriate handler to .htaccess, on our servers the following works:
    AddType application/x-httpd-php5 .htm .html
    Code (markup):
    Just ask your host for the information.

    If you rename .php to .html then yes you need to update the requires and includes.

    My advice just try a test before swapping the whole site.
     
    tolra, Feb 23, 2009 IP
  3. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think using .htaccess can solve the problem .
    It doesn't get involved with the host setting .
    How to write the .htaccess rules ?
     
    justinlorder, Feb 23, 2009 IP
  4. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #4
    What I gave you just goes in .htaccess
     
    tolra, Feb 23, 2009 IP
  5. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #5
    hi
    try this in .htaccess
    RewriteEngine On
    RewriteBase /
    RewriteRule ^([^\/]+)\.html$ /$1.php


    It will work

    Regards

    Alex
     
    kmap, Feb 23, 2009 IP
  6. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #6
    You need to add another rule to 404 the PHP files which is why I think it's going to be easier to just treat .html as PHP
     
    tolra, Feb 23, 2009 IP