skolind
skolind

Reputation: 1754

Changing URL with query string

I have been looking and looking around on the web for an answer for my question. But everything is just not the right thing.

So my issue is:

I'm creating my own CMS, and right now I've got the issue with the urls. They aren't really that SEO friendly.

When I create a new page, it gets the URL: index.php?page=(id). That doesn't tell much. So what I would love to create.

Is that I wan't the URL to be something like: www.myurl.com/home instead of the page=id. Is this possible?

I have to mention, that I need the id number later on, for editing the pages. I'm focusing the GET function to be able to edit my pages, and to show 'em one by one.

Thanks. :o)

Upvotes: 0

Views: 152

Answers (2)

ju5tu5
ju5tu5

Reputation: 36

Try to set your .htaccess file to the following:

RewriteEngine On
RewriteRule ^([^/]*).html$ index.php?page=$1 [L,NS]

this way you can translate what visitors see as yourdomain.com/home.html to what php reads as yourdomain.com/index.php?page=home afterwards you can of course use a translating array containing your id's

$translationArray("home"=>1, "contact"=>2);
$id = $translationArray[ $_GET['page'] ]; // $id now contains 1

Upvotes: 1

Halcyon
Halcyon

Reputation: 57709

What you're looking for is called Semantic URLs. Other keywords that will aid you: .htaccess, mod_rewrite

A full solution is too complicated to expand upon here but the underlying idea is fairly simple.

Upvotes: 1

Related Questions