Search Engine Friendly Urls generation with PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Search Engine Friendly Urls generation with PHP?

Post by Sindarin »

Can anyone tell me if it is possible to use PHP code to make/generate search engine friendly urls?
The site I am working on is on Windows server and I use switches to navigate through the site, like:

<?php
switch($_GET['page']){
case 'about':
$include= 'about.php';
break;
case 'contact':
$include = 'contact.php';
break;
case 'info':
$include = 'info.php';
break;
default:
$include = 'index.php';
}
include($include);
?>

So when I go to about page, the url is: http://site.com/index.php?page=about which isn't search engine friendly from what I read.

btw: where has the cool php code highlighter gone?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Search Engine Friendly Urls generation with PHP?

Post by s.dot »

You can manage this with PHP alone or with apache mod rewrites.

With PHP you can explode on the / in the URI path, with mod rewrite rules you can map query strings to more static looking uri's.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: Search Engine Friendly Urls generation with PHP?

Post by JayBird »

Sindarin wrote:btw: where has the cool php code highlighter gone?
It's coming back soon!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Search Engine Friendly Urls generation with PHP?

Post by Jonah Bron »

Whew! I was getting worried there for a minute. :mrgreen:
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Search Engine Friendly Urls generation with PHP?

Post by Kieran Huggins »

what you might want is a "router" in a front controller.

Take a look at the MVC pattern
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Search Engine Friendly Urls generation with PHP?

Post by Jonah Bron »

Also, I think it should be this:

Code: Select all

<?php 
switch($_GET['page']){
case 'about':
$include= 'about.php';
break;
case 'contact':
$include = 'contact.php';
break;
case 'info':
$include = 'info.php';
break;
default:
//Change this to some other page
$include = 'main.php';
}
include($include);
?>
The other way, the file includes itself.
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: Search Engine Friendly Urls generation with PHP?

Post by Sindarin »

:P I am not a scintilla lexer :lol:
Post Reply