Jump to content

.html URL's calling PHP, help plz!


gvanto

Recommended Posts

I would very much like to find out the implementation of:

www.myurl.com/myfile.html where this URL actually calls the location (and shows content) www.myurl.com/content.php?id=4

I have seen this done somewhere just cant remember where :-)

Any help much appreciated!

Gerry
Link to comment
Share on other sites

Umm, OK thought it was quite clear but here goes:

I have content in a database, and depending on the value of ‘id’ depends which content is shown. BUT, for each ‘page’ (ie. Page with different content, in reality still index.php), I want an HTML page as follows (ie. The html page is called / linked to / whatever):

url.com/myPage.html calls-> url.com/Index.php?id=4&someother=true
url.com/myRandomlyNamedOtherPage.html calls-> url.com/index.php?id=39&someother=blah

Hope this makes more sense,

Thanks,
Gerry


Umm, OK thought it was quite clear but here goes:

I have content in a database, and depending on the value of ‘id’ depends which content is shown. BUT, for each ‘page’ (ie. Page with different content, in reality still index.php), I want an HTML page as follows (ie. The html page is called / linked to / whatever):

url.com/myPage.html calls-> url.com/Index.php?id=4&someother=true
url.com/myRandomlyNamedOtherPage.html calls-> url.com/index.php?id=39&someother=blah

Hope this makes more sense,

Thanks,
Gerry
Link to comment
Share on other sites

Create 1 more column in table which you had stored those id's, name it url
Example of the table:
| id | url |
| 1 | url.com/12312vawafwa.html |
| 2 | url.com/2352g352vc352v352.html |
Etcs ...

In your index.php you should have:
[code]<?php
$id = $_GET['id'];
if (isset($id)) {
    function go_to_page($id) {
        $query = "SELECT * FROM `page` WHERE id ='$id'";
        $result = mysql_query($query) or die("Query failed: " . mysql_error());
        $row = mysql_fetch_array($result);
        $pageid = $row['id'];
        $pageurl = $row['url'];
        $go = "<META HTTP-EQUIV='refresh' CONTENT='0;URL=". $pageurl ."'>";
        return $go;
    }
    echo go_to_page($id);
} else {
    echo "You didn't select any page.";
    }
?>[/code]

Tell me if there's any error, I have test it yet.
Hope this helps.
Link to comment
Share on other sites

Dear Kear,

Thanks for your reply, but i just read up to here:
if (isset($id))

and immediately I sense that you have the INVERSE of the function that I want, fully explained.

In your code, you're expecting the user to enter: url.com/index.php?id=somenumber into the address bar, then call the .html file depending what this id is.

I'm looking for a way of: entering the .html file: url.com/myrandom.html which THEN calls url.com/index.php?contentid=something

Basically, a way of running a php file but which somehow has a .html extension (after which you can retrieve the current URL string, then FIND ID depending on the url location, ie. the inverse of what your code does)

Hope this makes more sense now. Any help much appreciated!
Gerry
Link to comment
Share on other sites

There's a way using .htaccess, but it's really trouble that a html file act as a php file.
Why not just use .php it's just 3 letters while .html 4 letters ?

[code]RewriteRule ^home\.html index.php [L]
RewriteRule ^index\.html index.php [L]
RewriteRule ^(.*)\.html index.php?write=$1 [L][/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.