homepage Welcome to WebmasterWorld Guest from 54.197.111.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Problems with the url on Blog pages.
Archiie




msg:4588895
 10:13 am on Jun 30, 2013 (gmt 0)

Hello,

I've got this problem which is;

My url on my blog is:

http://example.COM/blog.php?page=3

Is there any way to make it
( http://example.COM/blog.php/page/3 )

This is the code I use.

<?php
if($page <= $page_count && $page > 1 && $page != 2){
$next = $page-1;
echo ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $next . '"><img border="0" id=\'forgaende\'
src="http://example.com/forgaende2.png"
onmouseover = \'document.getElementById("forgaende").src = "http://example.com/forgaende1.png"\'
onmouseout = \'document.getElementById("forgaende").src = "http://example.com/forgaende2.png"\'
></a> ';
}
if($page == 2){
echo ' <a href="' . $_SERVER['PHP_SELF']. '"><img border="0" id=\'forgaende\'
src="http://example.com/forgaende2.png"
onmouseover = \'document.getElementById("forgaende").src = "http://example.com/forgaende1.png"\'
onmouseout = \'document.getElementById("forgaende").src = "http://example.com/forgaende2.png"\'
></a> ';
}
?>
</td><td align="right">
<?php

if($page < $page_count){
$next = $page+1;
echo ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $next . '"><img border="0" id=\'next\'
src="http://example.com/next2.png"
onmouseover = \'document.getElementById("next").src = "http://example.com/next1.png"\'
onmouseout = \'document.getElementById("next").src = "http://example.com/next2.png"\'
></a></a> ';
}

?>

- It's a simple (paging) but I would like it to become like the url I mentioned above.

Thanks,
Archiie

[edited by: incrediBILL at 4:32 pm (utc) on Jul 1, 2013]
[edit reason] unlinked URLs. exemplified [/edit]

 

lucy24




msg:4588903
 11:01 am on Jun 30, 2013 (gmt 0)

My url on my blog is:
{blahblah}
Is there any way to make it
{blahblah}
<snip>
but I would like it to become like the url I mentioned above.


You need to start by getting a firm grip on what you are doing. Afterward you can figure out the mechanics of how to do it.

If you're building your pages via php, it's safe to assume there is little-or-no relationship between the URL of a page and its physical filename. There may not even be a physical file.

Now, admittedly I only speak about three words of php, but I don't see the connection between the quoted code-- which seems to be entirely concerned with image files-- and pages. Unless your cat stepped on the keyboard and all those .png extensions are supposed to be .php

If you want your url to be
example.com/nicepage/3
then use that form in all your links. A quick line in htaccess-- or IIS equivalent-- will then rewrite it to something along the lines of blahblah.php?page=nicepage&number=3. And then your php takes over and makes the page, just the way it's already doing. Except that if one of the things your php does is make links, you have to be sure it's making them in the "nicepage/3" form.

The form
example.com/blog.php/page/3
is one of those weird neither-fish-nor-fowl URLs. If the object is to make it pretty and get rid of the query string, why not dump the ".php" too? It's not doing anything; as long as you're rewriting to something with a query string, your rewrite can perfectly well include tacking on a ".php" that isn't in the URL.

Archiie




msg:4589272
 3:52 pm on Jul 1, 2013 (gmt 0)

Lucy24, i'm sorry for not making it clear enough. Btw the .PNG files are images that are reffering to "Next or Prev page".

And how do I get rid of the ".php" in the url?

lucy24




msg:4589284
 4:25 pm on Jul 1, 2013 (gmt 0)

You can't "get rid of" something in an URL. You have to pick your preferred form and use it in the first place. If there's a request for the wrong form, redirect it. Then, when you get a request for "prettyfilename", rewrite to "uglyfilename.php?long-complicated-query".

The rewriting isn't done in php. (The redirect can be, though it usually isn't.) It has to happen in htaccess-- or, again, IIS equivalent-- before the request ever reaches your php file.

It is probably easier if you first explain in English, without code of any kind, what you want to do and what you want the human user to see.

incrediBILL




msg:4589287
 4:45 pm on Jul 1, 2013 (gmt 0)

Well, he's generating the HTML code here so the ".php" needs to be stripped out of the URL the PHP is writing.

You need something like this:
$url=str_replace ( ".php", "" , $url );

Then of course you need Apache rewrite rules to convert from no extension to .PHP

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved