Name a page as abc.htm while actual page is word.php?w=abc

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    Name a page as abc.htm while actual page is word.php?w=abc

    I have seen this many sites including theScripts, that page is actually .php with some get parameter, but the page can be found at an .htm page with no get parameter.

    How can that be done?

    eg. If you want to see a word say girl, and the PHP page showing this word is word.php?w=girl.
    I want to access the same page at girl.htm

    Wikipedia does something similar.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    The only reason to do this is to make it a lot easier to add new pages. Take the following and call that word.php[php]
    <?php
    $newpage=$_GET['w'].'htm';
    if (file_exists($n ewpage))
    header ("location: $newpage");
    else
    echo "page for $_GET['w'] does not exist";
    ?>[/php]and this one and call that girl.htm
    Code:
    <body>
    This a a girl
    </body>
    Now when I want to add a word e.g. boy, all I have to do is make some html file with the name 'boy.htm' and call it using word.php?w=boy.

    The actual code in word.php is a bit more complicated, but this is a very simplified version. I have used this to allow my users to add text pages (.htm) to the site.

    Was this the answer you were looking for?

    Ronald
    Last edited by ronverdonk; Mar 27 '08, 07:27 PM. Reason: code typo

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      Thanks, but I want the completely opposite thing.

      I mean I have a page word.php which reads the get parameter (w) and searches the database for that unique id (w) in a table, and displays the result.

      So to see details of any x word, which is in the database, word.php?w=x would work.

      But I want the result to be shown when the user types x.htm, instead of word.php?w=x

      This is what is done in Wikipedia, and here in theScripts too. This is actually very useful to get your site in the search engine's search results.

      A good familiar example is here...
      word.php?w=php
      php.htm

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        I believe that's a htaccess job, no?
        [code=apache]
        RewriteEngine On
        # start engine
        RewriteRule ^([a-zA-Z0-9])\.html$ word.php?w=$1
        [/code]
        Not sure whether that is syntactically correct, but it's the right logic.
        ;)

        Regards.

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by markusn00b
          I believe that's a htaccess job, no?
          [code=apache]
          RewriteEngine On
          # start engine
          RewriteRule ^([a-zA-Z0-9])\.html$ word.php?w=$1
          [/code]
          Not sure whether that is syntactically correct, but it's the right logic.
          ;)

          Regards.
          Even I think you are right, but need to try it first.

          And dude you still didn't find a solution to that scalability issue!

          Regards,
          Harpreet

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by hsriat
            Even I think you are right, but need to try it first.

            And dude you still didn't find a solution to that scalability issue!

            Regards,
            Harpreet
            Ah, that's a shame.. and you call yourself an expert ;)

            Regards

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by markusn00b
              Ah, that's a shame.. and you call yourself an expert ;)

              Regards
              I can't be blamed! I'm a JS expert... you the PHP expert B-)

              Regards
              Harpreet

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by hsriat
                I can't be blamed! I'm a JS expert... you the PHP expert B-)

                Regards
                Harpreet
                Have you had any luck with the .htaccess?
                I must do something right!!!!!

                Regards ;)

                Comment

                • hsriat
                  Recognized Expert Top Contributor
                  • Jan 2008
                  • 1653

                  #9
                  Originally posted by markusn00b
                  Have you had any luck with the .htaccess?
                  I must do something right!!!!!

                  Regards ;)
                  I didn't try it yet.
                  Had many other things to do. :(

                  Will tell you if it worked.

                  Regards

                  Comment

                  • aktar
                    New Member
                    • Jul 2006
                    • 105

                    #10
                    If you have access to the Apaches config file then all you need to do is tell Apache (assuming your server is Apache) to parse HTML files as PHP.

                    This is how its done:

                    [CODE=text]AddType application/x-httpd-php .html[/CODE]

                    In fact you can have ANY file extension for eg.

                    [CODE=text]AddType application/x-httpd-php .made_up_ext[/CODE]


                    The other way, as was mentioned earlier is .htaccess
                    However, you should avoid the .htaccess method as its extremely resource hungry. Thats why some shared hosting companies dont allow it to be used.

                    Hope this helps,

                    Regards

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      Originally posted by aktar
                      If you have access to the Apaches config file then all you need to do is tell Apache (assuming your server is Apache) to parse HTML files as PHP.

                      This is how its done:

                      [CODE=text]AddType application/x-httpd-php .html[/CODE]

                      In fact you can have ANY file extension for eg.

                      [CODE=text]AddType application/x-httpd-php .made_up_ext[/CODE]


                      The other way, as was mentioned earlier is .htaccess
                      However, you should avoid the .htaccess method as its extremely resource hungry. Thats why some shared hosting companies dont allow it to be used.

                      Hope this helps,

                      Regards
                      That isn't answering his question (although it is still interesting).
                      Hsriat wants the urls to be seen as one thing but be read as another, i.e. url rewriting (also know as: 'pretty urls').

                      regards :)

                      Comment

                      • aktar
                        New Member
                        • Jul 2006
                        • 105

                        #12
                        Oppsy, I see it now :)


                        With this rewrite concept, would you have to set a rule for every page you wish to rewrite?

                        Comment

                        • dlite922
                          Recognized Expert Top Contributor
                          • Dec 2007
                          • 1586

                          #13
                          Originally posted by aktar
                          Oppsy, I see it now :)


                          With this rewrite concept, would you have to set a rule for every page you wish to rewrite?
                          writing it for every page, kind of defeats the whole purpose.

                          what's wrong with you?

                          Your dancing around two issues: hiding extensions and pretty URLs.

                          they acomplish two different things.

                          Comment

                          Working...