-   Programming (
-   -   SEO: search-friendly URLs worth it? possible without extensive redesign? (

sneakyimp 03-26-2009 05:52 PM

SEO: search-friendly URLs worth it? possible without extensive redesign?
I'm working on an extensive site containing about 1000 PHP files. In addition to search pages and account pages and so on, a great many of these files accept numeric query string parameters:
Which might load up a school named "Occidental College" or perhaps a Career such as "Computer Programmer - Applications".

We are considering trying to alter the structure of our site to present more user-friendly URLs like this instead:

I completely understand how we might use mod_rewrite and some database work to map that URL onto However, I'm wondering a couple of things and would like some input.

1) If we don't change our internal links to a page (i.e., they still point to then this doesn't really help our search engine ranking unless external sites somehow know to link to the new fancy URLs, right? The perhaps futile hope is that we don't have to go change all the links in our 1000 PHP files and that we might use some mod_rewrite trickery to gain some advantage here.

2) Suppose I type into my browser. Is it possible to display the search-friendly URL ( in the browser instead so that if someone copies it to an email they get the long fancy URL?

2a) Is it possible to efficiently redirect a search engine looking for to and thereby gain all the advantages of our supposedly search-engine-friendly URL? Would we need to send an HTTP response code (301? 303?). Will the search engine be smart enough to know that the search-friendly URL is the 'real' link when it encounters the old-style link in the HTML of our site or somebody else's site? Does it help our ranking at all? What is the best technique for this?

3) I've heard that Amazon went from the query string / id approach to search-friendly URLs by using mod_rewrite type technology and ignoring the middle search-friendly part of a URL and putting the id part at the very end of the URL like this book called "Choke" by Chuck-Palahniuk.

This is what I think I should be shooting for and I understand how to accept the URL on our server and load up the right content, I do not understand how to capitalize on it to improve our search ranking. Thoughts?

4) Will this really help that much?

Any and all discussion of this is welcome and encouraged.

quixy 03-27-2009 12:54 AM

1) Yes, that is correct. If you don't change your internal links SEs would probably never know the long URLs. Yes and no, one part, that defaults to the 'no', is done by your app:


print("<pre>".print_r($_SERVER, true)."</pre>");
Call this script e.g. urltest.php and call it this way:

The second part has to be done by mod_rewrite (put this in .htaccess):


RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/(.*)_(.*)$ testurl.php?cat_name=$1&page=$2 [L]
Now call your script again with the long URL and compare the output:

You can also do this by ErrorPage 404 but I have heard that this is much slower.

As you can see the first call has only 'id=x' set, by the second has 'cat_name=x' and 'page=y' set. So you can may do something like this in a central place of your script (lets say ''?):


if (isset($_GET['id'])) {
// Old link found, load cat_name and page from DB!
$result = mysql_query("SELECT cat_name, page, title FROM some_table WHERE id=".(int)$_GET['id']." LIMIT 1");
if (mysql_numrows($result) == 0) {
// Not found!
header("HTTP/1.0 404 NOT FOUND"); // This header might be wrong, double-check it please...
die(); // This die() is important because w/o it you have a possible race-condition
list($cat_name, $page, $title) = mysql_fetchrow($result);
header("Location: http://your-site/".$cat_name."/".$page."_".$title);
die(); // Again required!

// Continue with finding the cat_name/page combination here, I leave it up to you. :)
2) Of course, once you have changed all internal links? I know, that will be a long or short night... :/

3) With my snippet above, no longer possible. It would result in an endless loop

4) Maybe, I'm not a SEO specialist, but I have heard too, that keeping the browser title in URL might also help. I extended my example a little, see variable $title for instance.

I hope that gives you a little idea...

Good luck,

sneakyimp 04-28-2009 03:39 PM

I have managed to get a pretty awesome rewrite going using mod_rewrite on a testing server. It will take this url:
and cause a 301 redirect (permanently moved) to this:
Additionally, mod_rewrite knows when it receives that 2nd url that it should internally rewrite it (no redirect) to the original file with a &rewrite=1 bit added to the query string. This works and attempts to visit the original page get 301 rewritten and then the 301 rewritten request with the SEO-friendly url will load the correct page with the correct data.

HOWEVER there is a problem. All the images, scripts, and links are broken in the resulting page because they are evaluated in the browser relative to the new-fangled seo-friendly page. How do you deal with this problem?

nazar20 11-19-2009 07:56 AM

Hire Drupal Developer
You can make search-friendly URLs the following types.

1.Ht Access.
2.Redirect the URL.
3..And try this code.
joomla redirection:
global $mainframe;
$link1 = "index.php?option=com_redirect";

4.Java Script:
<SCRIPT language="JavaScript">

pixellany 11-19-2009 01:23 PM

Not a Linux Question---off to Programming

sneakyimp 12-19-2009 01:00 PM

painful process
OK I have been working on this SEO thing for some time now and thank goodness I'm getting paid for it as it's really involved.

The optimization so far has required a variety of steps:
1) create rewrite rules in the .htaccess file to map the old ugly urls onto the new nice ones with a 301 redirect (permanently moved). Because the fancy new urls have information that doesn't exist in the old urls, this requires a RewriteMap directive so that I can query a database or text file mapping old info onto new ones.

2) create rewrite rules which internally map the fancy new urls onto my actual PHP files in a meaningful way.

3) alter all of my PHP code to link to the fancy new urls rather than the old ones. also add a <base> tag to my html output so that images, javascript, css, etc. will work. the base tag is necessary because my html code uses relative path references for images, js, css, etc. and the new urls' directory structure has nothing to do with the actual location of the files.

It's a total pain.

All times are GMT -5. The time now is 03:37 AM.