Dynamic URLs + SEO

Go To StackoverFlow.com

0

I have a website that generates dynamic urls for all content.

It uses a function to show the content on index.php page and it's called by "action".

So, if the user wants to signup, there is a signup function calling it. If the user want's to browse downloads page, there is a downloads function calling it.

Something like this:

index.php?action=signup
index.php?action=downloads
index.php?action=news&type=type&id=id

In the last case are the news. The news are divided by type and ID, both numerics.

Type can be: article, update, etc.

My question is: HOW and WHAT must I do in order to transform it all on friendly URLs?

2012-04-03 20:51
by Darkeden


1

Presuming you are on an apache server, you will want to use a .htaccess file, and a method of using rules to rewrite URLs, not surprisingly called RewriteRule.

There's a ton of information through google if you search for .htaccess RewriteRule, but a great starting point is http://corz.org/serv/tricks/htaccess2.php.

You will essentially end up by putting a file called .htaccess in your public web files folder, with something like this:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(?:/(.*)){1,3} index.php?action=$1&type=$2&id=$3 [R,NC]

Note: I've not tested the above, and it will differ depending on how you want your pretty link to look.

2012-04-04 14:03
by LeonardChallis
Well...thanks for your answer, but it isn't exactly what I need.

With some rewrite rules I can make "/register" avaliable, but it isn't enough, since I would need to manually update links.

Maybe you can help me to find out what I really need.

PROBLEM Current url: url.com/index.php?action=signup Desired url: url.com/register

How to make my website SHOWS "/register" as a link, not only as a possible path? I mean, when my website generates a dynamic link, it doesn't respect SEO rules. How to make it respects SEO? How to make it generates "/register" instead of "/index.php?action=signup" - Darkeden 2012-04-07 00:36

I think it does - but you need to add the extras, such as 301 redirects. All the information you need is in the page I posted, but it'll be something like: [R,301] at the end of your rules so it's only accessible from that one location, to avoid duplication - LeonardChallis 2012-04-07 08:31
Thank you. I could now understand what I need, so now I just need to implement. Help me to write two rewrite rules:

First - url.com/index.php?action=signup (url.com/register) Second - url.com/index.php?action=news&id=$id&title=$title (url.com/news/$id/title-of-the-notice-with-hifens)

Hifens will come from a PHP function or the rewrite rule? How to fix CSS problem after putting these dirs? How would be each rule - Darkeden 2012-04-10 15:55

The documentation does explain this, and the rest are out of the scope of the original question, but here's something to get you started:

RewriteRule ^register$ index.php?action=register RewriteRule ^news/(\d+)/([a-zA-Z0-9-]+)$ index.php?action=news&id=$1&title=$2

Note: This will not work if you have a trailing slash - you can figure out what you want to do here (either add one optionally with /? or just create another rule to not allow them, for instance)

In your CSS you will have to just change the paths to reflect what the browser will now see. Use absolute paths, starting with a - LeonardChallis 2012-04-10 17:36

Thank you for your attention and support. Every small error was sorted out (CSS, hyphens, rewrite rules) and you has a guilt on it ;). Thank you - Darkeden 2012-05-26 19:46
Let me disturb you a more few with two questions. 1- If I use your first rule (RewriteRule ^(?:/(.*)){1,3} index.php?action=$1&type=$2&id=$3), how it would looks like on my website? - 2- How to create permanent redirects? (ex: url.com?action=signup -> url.com/signup)? - I tried your [R,301], but it didn't solved. I also tried some other tricks that I found over the net, but also didn't worked - Darkeden 2012-05-26 19:48
Ads