Oliver Spryn
Oliver Spryn

Reputation: 17368

Search-Engine Friendly URLs

I am working on building my first search-engine friendly CMS. I know that perhaps one of the biggest keys to having and SEO site is to have search-engine friendly URLs. So having a link like this:

http://www.mysite.com/product/details/page1

will result in much better rankings than one like this:

http://www.mysite.com/index.php?pageID=37

I know that to create URLs like the first one, I have one of two options:

As far as the PHP goes, I'm pretty comfortable with anything. However, I think the first option would be more difficult to maintain.

Could someone show me how to write an .htaccess file, which will:

Is there a better way than the way I am trying it?

Upvotes: 3

Views: 620

Answers (2)

Nick ODell
Nick ODell

Reputation: 25454

Yes, the first option would be pretty hard to maintain. If you want to change the header of the pages, you'd need to recalculate all of the pages.

The simplest way to do that would be to have a PHP file named product.php or product/details.php and use the $_SERVER\['PATH_INFO'\] variable to figure out what the client requested.

Upvotes: 0

Senad Meškin
Senad Meškin

Reputation: 13756

You can use .htaccess for apache, create file in your root folder of web mainly "htdocs" name it ".htaccess" add next content to it

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    Options -Indexes
</IfModule>

in your php file you can access data from $_GET

$_GET['url'];

Then you can use data to parse what you need.

Upvotes: 7

Related Questions