User Login





Register
Forget Password

Hostings with very low prices

Hosting Plans Starting at 1$/Month

BaydHost

Powered By

  • AhmBay
  • Using Apache's Rewrite Engine with vhosts enabled - Apache Webmaster Tips, Knowledge Base Webmaster Tools

    Home > Apache > Using Apache's Rewrite Engine with vhosts enabled
    Category: Apache
    Written by: Admin
    Date: 2008-11-16
    Rating: 0   Puan:0 | Katılımcı:0 | Voted : 0 times
    Hit: 468
      

    I am currently working on a project for a customer where I'm converting it from a static html site to a database driven site with a search engine and a consultant's name find function. I am using Codeigniter for this project, which uses Apache's mod_rewrite feature, but had some issues when I uploaded the project to the customer's web host due to it being set up with vhosts. Apache's rewrite engine allows urls to be rewritten from what appears to the browser to something different which Apache will actually process.

    On my development machine this worked no problems with the following .htaccess file:

    # start the rewrite engine
    RewriteEngine On

    # we skip all files with .something
    RewriteCond %{REQUEST_URI} \..+$
    RewriteRule .* - [L]

    # testing version of the site
    RewriteRule ^testing(.*)$ testing.php$1 [QSA,L]

    # redirect to our front web controller if nothing above matches
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]

    The useful .something rewrite condition means that any file with a dot in it will be ignored by the rewrite engine and left to Apache to attempt to serve it instead. Everything else will be run through the frontend controller in the index.php file.

    When I uploaded this to the customer's web host (Web Drive), it wouldn't work, giving me an error like this:

    The requested URL /httpd/vhlinks/[domain-name]/index.php/ was not found on this server.

    where [domain-name] was the customer's domain name.

    I spent a short amount of time searching for an answer. Web Drive use vhosts mapping (I'm not all that familiar with how this works, not having ever set up a web server in this way), but all I needed to do to make it work was to change the main Rewrite Rule to contain a %1 as follows:

    RewriteRule ^(.*)$ %1/index.php/$1 [QSA,L]

    I re-uploaded my changes and then it all worked fine.