how to change .php tp .html

8 replies
Hello warrior senior.Im looking for the solution to change all the url from current .php to more nice .html.Now my web url will be like www.mydomainexample.com/view_news.php?id=58 and i want to change it to www.mydomainexample.com/news/no-id-number-but-the-exact-file-name.html

I want to call id number of that post to be the file name or news.Please someone help me
#change #html #php
  • Profile picture of the author minirich
    This sounds like a job for url rewriting. If you are using Apache, you can use the mod_rewrite.
    Either in your vhost conf file or in your htaccess files in your directory.
    It will parse the url and split it and then recreate your php query.
    You can even leave the html off.
    Put this line in your vhost.conf or .htaccess file:
    Code:
    RewriteEndgine on
    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)$ /$1.php?id=$2 [L]
    The result will look something like this:
    www.yourdomain.com/news/221 => www.yourdomain.com/news.php?id=221
    www.yourdomain.com/article/40 => www.yourdomain.com/article.php?id=40
    www.yourdomain.com/post/33210 => yourdomin.com
    Even this url will be translated
    www.yourdomain.com/332/my_new_post => www.yourdomain.com/332.php?id=my_new_post.
    Propbably not what you had in mind but it will work also.

    If you do not have access to vhost.conf try the .htaccess in your route dir.
    Or ask your webmaster/host provider for support.

    Hope that helps
    Mike
    {{ DiscussionBoard.errors[9378165].message }}
  • Profile picture of the author minirich
    This rewrite rule is only for incomming requests.
    That means if you write put the address www.yourdomain.com/news/221 in your browser your request gets forwarded to the php page.

    If you have a link on your page you have to change them in an other way.
    Probably in you cms or in you php code.

    Mike
    {{ DiscussionBoard.errors[9379317].message }}
  • Profile picture of the author bjadams
    create an html doc named no-id-number-but-the-exact-file-name.html
    in the html doc have a frame take 100% of the page
    in the frame load the php
    {{ DiscussionBoard.errors[9379379].message }}
    • Profile picture of the author minirich
      Originally Posted by bjadams View Post

      create an html doc named no-id-number-but-the-exact-file-name.html
      in the html doc have a frame take 100% of the page
      in the frame load the php
      This is a way to solve the problem but it is very cumbersome, because for every page a html file has to be created.
      Mike
      {{ DiscussionBoard.errors[9379424].message }}
      • Profile picture of the author bjadams
        Originally Posted by minirich View Post

        This is a way to solve the problem but it is very cumbersome, because for every page a html file has to be created.
        Mike
        i thought you only had 1 page to fix!
        {{ DiscussionBoard.errors[9379619].message }}
        • Profile picture of the author aeroponica
          my web is create with core php so the resulting url in the php format.But i think this is a content informational website will be more search engine friendly if i can change it to .html. But still cant find how to do this.Any suggestion will be appreciated.
          Signature


          {{ DiscussionBoard.errors[9380291].message }}
  • Profile picture of the author MWells
    Hi, you can do it:

    Add this line into your .htaccess file:

    AddType application/x-httpd-php .htm .html .php

    This means that the server will run any file ending .htm, .html and .php as if it ends with .php

    However the downside is that it will slightly increase server loads as all files will be run as .php, even if they dont actually contain any PHP code.

    If you are passing a lot of variables through the URL then I would Google "mod_rewrite" and see if you can find a tutorial on that.

    I hope this helps you
    {{ DiscussionBoard.errors[9379465].message }}

Trending Topics