Hi I am building my own blog software and I am trying to remove a query string from a php url, for example: www.mysite.php/blog.php?blog_id=1&this-is-the-blog-title would be good if i can change to this: www.mysite.php/blog.php/blog_id=1/this-is-the-blog-title is this possible? and will it help my seo? Ive heard that bots cant navigate through links with query strings in them! any help or pointing in the right direction would be very much appreciated!
I do something very similar on some of my websites. I have a url like http://www.mydomain/index.php/pagename1/subpagename1/subpagename2 $pages = explode('/',substr($_SERVER['REQUEST_URI'],1)); PHP: if you do a print_r on pages you will get this Array ( [0] => index.php [1] => pagename1 [2] => subpagename1 [3] => subpagename2 ) PHP: This means you can access all the parts via the array $pages. And if you want you can create a single rewrite rule and get rid of the index.php as well
What is complicated? that is one line of code that you use and then if you normally have a query like this $sql = 'SELECT * FROM blog WHERE id='.$_GET['blog_id'].' LIMIT 1'; PHP: you do it simply like this $sql = 'SELECT * FROM blog WHERE id='.$pages[1].' LIMIT 1'; PHP: Do you really call this complicated?
no the url is coming from a link in a script. I have 1 page that is serving all of my blog entries, so i want it to show the the blog title coming from a variable in the url, taken from a database: <a class='blog_title' href='view_blog.php?post_id=$post_id&$post_title_link'>$post_title</a> i'm not sure how the sql would affect the page url? which is: $sql = "SELECT * FROM blogs WHERE post_id = $_GET[post_id]"; which is why i didnt really understand your comment.
Well if you do it the method I suggest then this is what will happen change <a class='blog_title' href='view_blog.php?post_id=$post_id&$post_title_link'>$post_title</a> $sql = "SELECT * FROM blogs WHERE post_id = $_GET[post_id]"; to <a class='blog_title' href='view_blog.php/$post_id/$post_title_link'>$post_title</a> $sql = "SELECT * FROM blogs WHERE post_id = $pages[1]"; done and dusted.
ive changed as you said and now i get this: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1?
Ok have you done some debugging? please post the following: The actual url displayed in the address bar The explode function The print_r of the array The SQL you tried to run
the sql: $sql = "SELECT * FROM blogs WHERE post_id = $pages[1]"; whats an explode function? how do i run that? how do i print_r the array?
OK lets take it really easy as you seem not to get things. 1. I provided you with some code $pages = explode('/',substr($_SERVER['REQUEST_URI'],1)); PHP: Have you done any changes to this? If so please paste your code. 2. Lets check if that code above works. put the code below right after the above code print_r($pages); PHP: 3. Lets check that the sql is cone properly. After you build the sql place this code echo $sql; PHP:
right, sorry but i missed out a vital piece of code: $pages = explode('/',substr($_SERVER['REQUEST_URI'],1)); i added this before my sql statement and now it works. cheers for your help and patience!!
No problem. Since appear to do web development let me give you a small advice that can save you hours and hours of banging your head against the wall if something doesn't work. DEBUG!!! Always output code stuff that will show you if values are properly carried over and functions return correct info. Glad it works.
Just one little idea. You could change the url to something more like this http://www.enetdesign.co.uk/blog/High-PR-dofollow-blogs-and-forums-list-8 but I leave it up to you to figure it out
debug..i get ya, lol!! im quite new so just soaking everything up! ill have a go at changing the url as suggested! cheers again!