Jump to content

Search Engine Friendly URLs


.Darkman

Recommended Posts

Hello Everybody,

 

I am developing a Blog system. I am doing it for two reasons :

1) To Learn more about PHP

2) Wordpress and other systems are too sophisticated for me.

 

I need some help in getting Search Engine friendly URLs.

 

For eg, I have a Post's title as "A New Post".

That is entered into one field of the DB.

 

I want to insert into another field as "a-new-post" so that i can use it in URLs.

 

Could anyone advice me how to do it ?

Also what can be done if the Title contains some special characters.

 

Please do explain in detail. I am Newbie.

 

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/41613-search-engine-friendly-urls/
Share on other sites

This is pretty simple with .htaccess rewrite rules.

 

Apache will look at the URL and then translate it for you, your .htaccess file will look like:

 

 

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^blog/(.*).html /index.php\?val=$1 [nc]

 

So what this does is when someone browses:

 

http://www.site.com/blog/my-first-blog.html

 

Apache translates this and calls:

 

http://www.site.com/index.php?val=my-first-blog

 

So then in index.php you can do:

 

<?php

echo $_GET['val'];

?>

 

and you get 'my-first-blog', so then you can do:

 

SELECT * FROM my_blog WHERE title LIKE '$_GET['val']'

 

WARNING - SQL injection error in the above code (use mysql_escape_thingy() )

 

Now search google and post some more comments in this thread!!!

 

http://www.google.co.uk/search?num=100&hl=en&q=.htaccess+rewrite+pretty&btnG=Search&meta=

 

monk.e.boy

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.