/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] SEO Links?

I read some checklist for SEO. It says you shouldn’t have “?” in your links.
One of my websites is database driven and written in php. My links are basically like this:

[url]http://www.domain.com/content.php?id=16[/url]

How to do I change the ?id= to something like:
[url]http://www.domain.com/content.php/id/16[/url]

I would like to be able to do this without having to rewrite much of my code.

Here is the code:

[code=php]<?php

include(“dbconnect.php”);

$id=$_REQUEST[‘id’];
$start=$_REQUEST[‘start’];

$sqlprop=”Select * from Content where ContentID=’$id’ LIMIT 1″;
//$resprop=mysql_query($sqlprop,$db);
$resprop=mysql_query($sqlprop);
$oneprop=mysql_fetch_object($resprop);
$row = mysql_fetch_array($resprop);
?>[/code]

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 01.2007 — If running on an Apache web server, do a search on "apache mod_rewrite". If that's not an option, at the very least use something other than "id" as the variable name in the URL, as Google specifically ignores that, but will likely follow the link if it's something else and is short and simple, such as "?page=16".
Copy linkTweet thisAlerts:
@pcthugApr 01.2007 — Well first, that code is susceptible to sql injection, try this code instead:
[code=php]
<?php

include("dbconnect.php");

$id=$_REQUEST['id'];
$start=$_REQUEST['start'];

$sqlprop = sprintf('Select * from Content where ContentID = %d LIMIT 1', $id);
//$resprop=mysql_query($sqlprop,$db);
$resprop=mysql_query($sqlprop);
$oneprop=mysql_fetch_object($resprop);
$row = mysql_fetch_array($resprop);
?>[/code]

As for the SEO Friendly links, this is done at the webserver level, Apache's mod_rewrite is commonly used. Create a file named [font=courier new].htaccess[/font] and place the following code within:
<i>
</i>RewriteEngine On

# content.php/id/16/
RewriteRule ^content.php/id/([0-9]+)/?$ content.php?id=$1

Now just change your links to adopt the new format.
Copy linkTweet thisAlerts:
@pcthugApr 01.2007 — ... If that's not an option, at the very least use something other than "id" as the variable name in the URL, as Google specifically ignores that, but will likely follow the link if it's something else and is short and simple, such as "?page=16".[/QUOTE]Although that was once the case, Google has recently stated that they accept such links just fine. [[url=http://googlewebmastercentral.blogspot.com/2006/10/update-to-our-webmaster-guidelines.html]link[/url]].

So rewriting URL's have become much more of a web 2.0 cliche, rather than a SEO technique.
Copy linkTweet thisAlerts:
@gc40authorApr 01.2007 — Thanks for the tips about the SQL injection, although I don't see how changing 'id' to %d would help anything?

Also, the .htaccess file has been updated with the code you provided with no results.
Copy linkTweet thisAlerts:
@pcthugApr 01.2007 — Thanks for the tips about the SQL injection, although I don't see how changing 'id' to %d would help anything?[/QUOTE]It formats the id variable as a decimal so only numeric characters will be added to the query thus eliminating the chance of SQL injection.

Also, the .htaccess file has been updated with the code you provided with no results.[/QUOTE][LIST=1]
  • [*]Are you running on an mod_rewrite enabled Apache server?
  • [*]What is the URI you are navigating to/what is the resulting page?
  • [*]Can you verify that the query-string equivalent works?
  • [/LIST]
    Copy linkTweet thisAlerts:
    @gc40authorApr 01.2007 — 
  • 1. Are you running on an mod_rewrite enabled Apache server?

    YES.


  • 2. What is the URI you are navigating to/what is the resulting page?

    http://www.domain.com/content.php?prop=16


  • 3. Can you verify that the query-string equivalent works?

    Explain?


  • [CODE]RewriteEngine On
    # content.php/prop/16/
    RewriteRule ^content.php/prop/([0-9]+)/?$ content.php?prop=$[/CODE]


    p.s. How have you been PCThug? Haven't heard from you in a while. Come on MSN at some time dude.
    Copy linkTweet thisAlerts:
    @pcthugApr 01.2007 — RewriteEngine On
    # content.php/prop/16/
    RewriteRule ^content.php/prop/([0-9]+)/?$ content.php?prop=$[color=red]1[/color]
    Try that code and then navigate to [font=courier new]content.php/prop/16/[/font]
    Copy linkTweet thisAlerts:
    @gc40authorApr 01.2007 — No luck. I copied the code exactly as you have it.

    I also know the modrewrite is on because my wordpress blog does what I am trying to learn now.
    Copy linkTweet thisAlerts:
    @gc40authorApr 01.2007 — Great, thanks a lot.
    Copy linkTweet thisAlerts:
    @gc40authorApr 01.2007 — Alright, so it works. Although, I thought it would have worked differently.

    I was clicking a link: www.domain.com/content.php?prop=16, rather than typing www.domain.com/content.php/prop/16 in my browser. That means, I must change all of my link refferences in my html files.

    Lastly, I realised that my absolute path is not recognized. My css was listed as just:

    <link href="styles.css" rel="stylesheet" type="text/css" />

    I had to change it to:

    <link href="http://www.domain.com/styles.css" rel="stylesheet" type="text/css" />

    Because the mod rewrite wasn't allowing my css to be included. Weird?
    Copy linkTweet thisAlerts:
    @pcthugApr 01.2007 — No, because your browser doesn't distinguish between a mod_rewrite [I]dummy[/I] directory and a real directory, so your browser was looking for [font=courier new]styles.css[/font] in [font=courier new]www.[B][/B]domain.[B][/B]com/content.php/prop/16/[/font] ([font=courier new]www.[B][/B]domain.[B][/B]com/content.php/prop/16/styles.css[/font]) rather than [font=courier new]www.[B][/B]domain.[B][/B]com/styles.css[/font]. So naturally, you must identify that you are referring to your webroot by either including a leading forward-slash (/) or reference the css file with the entire absolute path, i.e. [font=courier new]http://www.[B][/B]domain.[B][/B]com/styles.css[/font]

    The above is also true for any other external media, i.e. Images.
    Copy linkTweet thisAlerts:
    @gc40authorApr 01.2007 — Ah, understood.

    Now the next question is how do I change the

    RewriteEngine On

    # content.php/prop/16/


    RewriteRule ^content.php/prop/([0-9]+)/?$ content.php?prop=$1

    from /prop/16 to match all of my new additions?

    Must I write a new line for every database entry?

    e.g.

    RewriteEngine On

    # content.php/prop/9001/


    RewriteRule ^content.php/prop/([0-9]+)/?$ content.php?prop=$1

    ??
    Copy linkTweet thisAlerts:
    @pcthugApr 01.2007 — Currently, the code will match any number. I'll try to explain;

    [0-9] allows any character between 0-9 (0123456789) and the + sign means 1 or more of the previous character so the current code allows... 1 or more characters between 0-9. Thus, any number will suffice.

    If you'd like to allow other patterns, please explain there format and I will pass on the relevant code.

    BTW [FONT="Courier New"]# content.php/prop/16[/FONT] is just a comment
    Copy linkTweet thisAlerts:
    @gc40authorApr 01.2007 — I got it. Haha, I can't believe that was just a comment. I feel stupid ..Haha. Thanks bro.

    Ah, wait, one more question, must I update the link names of my links or will the mod rewrite change the link name when the person clicks on it. (in their navigation that is).
    Copy linkTweet thisAlerts:
    @pcthugApr 01.2007 — Your going to have to change all your links to make use of the SE friendly format.
    Copy linkTweet thisAlerts:
    @gc40authorApr 01.2007 — Ah, Ok, thanks mate ?
    ×

    Success!

    Help @gc40 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.5,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...