Friendly URL without mod_rewrite
After while away from thyphp, I am back
and continuing with the a saga of SEO (Search engine optimization) focusing on Friendly URL.
In this post I will continue Friendly URL! is it really needed? but focusing on performance with Apache.
The most common way to have friendly URL is with the mod_rewrite, which is an Apache web-server module. This Apache module accept regular expressions and transform to a local file (normally a php-script
).
RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]
That configuration could be in the Apache’s configuration file (httpd.conf) or int the “.htaccess” file (or “distributed configuration files”). The htaccess provides a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system. The main reason is because the htaccess is interpreted for every request and the main configuration (httpd.conf) is compiled when the server startup.
The better solution for have friendly URL is to have all the mod_rewrite regular expression on the httpd.conf, that have a benefit of performance, but for every change we must restart the apache webserver.
Another valid solution is the class URL Rewriter Class which redirect all not found pages to a PHP script, and that script has regular expression for match a given page. This solution work with mod_rewrite.
But what happened if we don’t have mod_rewrite on our server, we don’t like regular expression, or we’d like to avoid it for a performance issue. There exist a way that I saw on the PHP Classes site in this post where Manuel Lemos (PHP Classes site admin) response my answer about the site URL handling.
If we have a page http://foobar.com/blog.php the test.php with Apache ( I don’t know about other webservers) we can extend the URI as, http://foobar.com/blog.php/this-is-a-friendly-url.html. In blog.php script we need to work with $_SERVER[’REQUEST_URI’] ( in this example its value /blog.php/this-is-a-friendly-url.html).
Obviously have a blog.php in as a “directory name” is not so beauty, anyone know that blog.php is an php-script. To solve this “look” problem, apache come with a feature called “MultiViews”. You can add this feature on the httpd.conf or in the worst in “.htaccess” file.
Options Multiviews
With this feature will be able to have friendly URL such as http://foobar.com/blog/this-is-a-friendly-url.html with less effort, we manage everything with a greater performance.
Also to help with parsing URL, I recommend to extract what you need from this class.
I hope you like this post!
See you soon on others post! ![]()
23 Comments
Leave a comment







Multiviews can nullify your search engine rankings: http://www.gerd-riesselmann.net/archives/2005/04/beware-of-apaches-multiviews
While there is a fix for Apache 2, its not without problems as well, and god forbid that your script should decide to send back anything not text/html:
http://tranchant.plus.com/notes/multiviews
People are also working around these problems using rewrite rules, but doing that defeats the purpose of the technique described.
Thankfully mod_rewrite is my friend
Hello,
I try with Multiviews, and it responses 200, I use Apache 2.
I’ll do my test on apache 1.3 to see if it responses 404 or 200.
Regards
HI,
My server doesnt have mod rewrite , how to use that class file to redirect my web pages ..
Please can u explain me bcoz i am not very good in php .. but iknow basics …
Thanks in advance…
saravanan.B,
given an example of how you want your URL looks like…
HI,
thank u for showing interest and my site url is
http://www.designscripting.com/articles/news.php?news=7
it will we very helpfull
thanks again
Hi,
Can be the resulting url will be search friendly
Thanks………………………………. a lot
saves my day writing rewrite rules ^^
Hello Cesar, You have a really nice post on implementing SEO URLs without Apache’s mod_rewrite() module.
Why don’t you post your PHP classes, scripts, tutorials and articles at http://www.search-scripts.com ?
Hi,
very nice script, but I wonder if the mod_rewrite is disabled on the server, why the MultiViews feature would be enabled.
videosblog.netkatarakta.html
videosblog.nettumenmehanizaciya.html
videosblog.netvystavki-vina.html
videosblog.netvideokamery-acti-otzyvy.html
It Has Great ResourcesGreat Job, Keep up the good work, canadian free online dating services, canadian free online dating services, uyja,
Hello!,
hi i have tried to implement this in to my own cms and it has been giving me odd erros, can u tell me if my code is correct please
url_handler.php
error_reporting(E_ALL);
require “url_rewriter.php”;
$url = new url_rewriter(’./’);
$url->e404 = “index.php”;
//$url->add_rule(”tutorails.php”,”/tuts/cat/[tutcat]”);
$url->add_rule(”tutorails.php”,”/tuts/cat/[tutcat]/name/{[tutname]}”);
/* execute and search pattern */
$url->execute();
tutorails.php
$tutcat = $urlVars[’tutcat’];
$tutname = $urlVars[’tutorails’];
if (!$tutcat && !$tutname) $urlHandler->error404();
buy viagra buy viagra
tohatesmbd.guts
You Must See This
You Make Me Want MoreReally Interesting, Indulging Website
It Has Great ResourcesGreat Job, Keep up the good work
byanychanse
Check itYou Must Look In This Website
well, hi admin adn people nice forum indeed. how’s life? hope it’s introduce branch
Very nice information. Thanks for this.
Regards,
Jane
Great helpful information, Thanks for this nice post, just subscribed your feed, hope you will update new post soon.
keep it up.
Aaron.