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! :)

11 Comments

  1. Comment by Spacebat on December 17, 2007 10:41 am

    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 :)

  2. Comment by Cesar D. Rodas on December 17, 2007 1:12 pm

    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

  3. Comment by saravanan.B on December 22, 2007 2:33 pm

    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…

  4. Comment by Cesar D. Rodas on December 22, 2007 2:43 pm

    saravanan.B,

    given an example of how you want your URL looks like…

  5. Comment by Saravanan.B on December 24, 2007 10:56 am

    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

  6. Comment by Saravanan.B on December 24, 2007 11:08 am

    Hi,
    Can be the resulting url will be search friendly

  7. Comment by Superbiji on January 2, 2008 2:14 am

    Thanks………………………………. a lot

    saves my day writing rewrite rules ^^

  8. Comment by Search Scripts on January 12, 2008 2:46 am

    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 ?

  9. Comment by Handy on April 9, 2008 9:19 am

    Hi,
    very nice script, but I wonder if the mod_rewrite is disabled on the server, why the MultiViews feature would be enabled.

  10. Comment by Timmy on May 10, 2008 4:06 am

    videosblog.netkatarakta.html
    videosblog.nettumenmehanizaciya.html
    videosblog.netvystavki-vina.html
    videosblog.netvideokamery-acti-otzyvy.html

  11. Comment by SZgLS on June 25, 2008 8:07 pm

    It Has Great ResourcesGreat Job, Keep up the good work, canadian free online dating services, canadian free online dating services, uyja,

Comments RSS

Leave a comment