-2

hi guys iam new to 'php', i just wanted to know how to make this url into seo friendly.

iam sending two values to post.php page

<a href='post.php?id=$pid&title=$title'>Read More....</a>

when i click on read more....

the url to post.php must look like this post/$title(title of that post)

current url looks like http://fotoshoots.be/blog/post.php?id=14&title=test

but i want the url like like http://fotoshoots.be/blog/post/test

plz help me

user1844933
  • 3,296
  • 2
  • 25
  • 42
user3219680
  • 49
  • 1
  • 1
  • 4
  • I suggest using the following solution: http://stellarbuild.com/blog/article/making-a-blog-url-seo-friendly-with-php a totally different approach. – msj121 Apr 01 '15 at 14:38

2 Answers2

0

Well, you need two things: You need a "router" : PHP scripts which receive all the requests and parse it back to $_GET https://github.com/dannyvankooten/AltoRouter is a good one

the second thing is to print all URLs in the desired format e.g: /blog/page-title-here

osmancode
  • 291
  • 2
  • 6
0

just use mod_rewrite. create a .htaccess file in the Directory blog with following Content:

RewriteEngine on
RewriteRule ^post/([a-zA-Z0-9_-]*)$ post.php?title=$1 [QSA]

i dont know how much you know about regex, but every request that Looks like "post/your-title-here" will be replaced by post.php?title=your-title-here. please notice that this Kind of "internal Redirect" cannot find the id Parameter, post.php has to find it itseld by $title. currently the file would just allow latin characters, numbers, "_" and "-" in the request, you can Change that by changing the Content of the two square brackets according to regex rules. i hope i could help you.

Sirac
  • 693
  • 4
  • 18
  • Thank you for your quick responce, i tried it but it is not working it is giving me same output – user3219680 Jan 21 '14 at 15:04
  • since i dont think you changed the file Content, check the filename: it MUST HAVE the name ".htaccess" and lie in the Directory "/blog". i also found out the title-Parameter is not relevant for the request, so you could sort your articles by title and drop the id, or rewrite /post/22 to /post.php?id=22 with this code: `RewriteEngine on RewriteRule ^post/([0-9]*)$ post.php?id=$1 [QSA]` – Sirac Jan 21 '14 at 15:21