SEO URLs without mod_rewrite and FilesMatch
Many CMSs solve the need for Fancy
URLs (URLs that are easy to follow by the user, and favoured by Search
Engines as well) by using mod_rewrite
, and/or FilesMatch
(available
only on Apache), or both.
Common solutions:
E.g., to get $itemid
from URL like http://../article/this-is-a-title
we
need to create following .htaccess
file:
<FilesMatch "^article$"> ForceType application/x-httpd-php </FilesMatch>
In this example we are forcing /article/
part of the URL to be
processed as a PHP application.
Next, we will create a new PHP file called article
(without .php
extension), which will process the URL, and determine proper article number,
and pass the control to our CMS.
<?php // some internal function include ('somecommonfncs.php'); // get article id $itemid = getItemIdFromName($_SERVER['REQUEST_URI']); // and process it processIt(); ?>
Seems easy, right? Well, this solution has several big problems in real-life, especially when open-source projects and code portability are concerned.
Problems:
FilesMatch
is not available under Microsoft IIS, it works fine only with Apache, thus this solution may not run at your selected web-hosting company (if they do not use Apache),- Even if your webhosting company does use Apache HTTP server, you may not
be able to access/create
.htaccess
, or it costs you more money to be able to modify it, - Some browsers (namely, MSIE) behave in a very strange way when downloading
CSS files again for URLs modified in a runtime by
FilesMatch
, - Google Page Rank (GPR) is different for the domain, and for the article fancy URL, if somebody is linking to your article, it does not even fully add to Google Page Rank value of a domain!
Solutions:
Instead of using FilesMatch, and .htaccess
file, we will use
simple $_GET
variables. Our final URL will look like:
http://domain.com/?article=this-is-a-title
And code will look like:
<?php // some internal function include ('somecommonfncs.php'); // get article id $data=$_GET['article']; if (isset($d)) $itemid = getItemIdFromName($data); // and process it processIt(); ?>
Same approach can be applied for member ids, archivelists ids, category ids, and many others.
This approach does have many advantages and no short-commings:
- This SEO-friendly solution does work with any web-server configuration,
be it Apache, and/or IIS, with or without
mod_rewrite
, - Google Page Rank for your domain increases, even when linking to an individual article,
- Browsers (MSIE) do not reload CSS files again and again,
- You can safely use international characters in URL parameters, thus improving your Page Rank even more.
You can see example of these new fancy URLs at http://demo.blogcms.com/.
BLOG:CMS is an open-source Personal Content Management System, licensed under GNU GPL, developed by Radek Hulán.
Well, I've read somewhere that many Search Engines (but Google) don't really count with URLs with '?'; (the one before Query String :)). I don't know how it is true, but I think your solution is one of the best if you can't use mod_rewrite or anything.
I've thought about it, too. Have not implemented by myself but seen on some websites already: why not use the same way as you do but:
http://web/?/article/the-title/
. Or other type of customized Query String likehttp://web/?/article:the-title
. The one with slashes is more like the use of mod_rewrite. What do you think about it?Your code:
<FilesMatch "^article$">
ForceType application/x-httpd-php
</FilesMatch>
I don't know why it's like this. If you "parse" just one file, you don't have to use regexp. So my version:
<Files article>
ForceType application/x-httpd-php
</Files>
[2] this examples's taken from BLOG:CMS source code, and simplified, it does make sense in the whole picture ;-)