.php to .html show in Web URL

Discussion in 'PHP' started by rahulsingh, Apr 21, 2008.

  1. #1
    Hi
    i have a website there is 5000 pages .php format what i want all php file serve as html if someone type filenam.html then its will serve filename.php.

    i am godaddy on hosting can any tell me what can do with .htaccess file.

    Thanks
     
    rahulsingh, Apr 21, 2008 IP
  2. Randombase

    Randombase Peon

    Messages:
    224
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Little htaccess magic:
    RewriteEngine on
    RewriteRule (.*)\.html $1\.php
    Code (markup):
    :)
     
    Randombase, Apr 21, 2008 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    If you're web site already exists, I assume some search engines have the pages indexed already and with the .php extension, which could result in "duplicate content" and lost page rank. You probably want to supplement Randombase's solution with the following:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^(.*)\.php
    RewriteRule .* %1.html [R=301,L]
    RewriteRule (.*)\.html $1\.php [L]
    Code (markup):
    What that does is make sure the user is seeing the pages with the .html extension. If they go to filename.php, they will be redirected to filename.html which will then serve the PHP file transparently.

    Do you need to handle query strings Rahul? You may need these, if not just for session handling, in which case you will need to do a little more, namely adding QSA flags to the rewrite rules and making sure they are still served SEO friendly to the search engines.
     
    krt, Apr 21, 2008 IP