CodeIgniter Forums
mod_rewrite, conditional RewriteBase? - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: mod_rewrite, conditional RewriteBase? (/thread-25607.html)

mod_rewrite, conditional RewriteBase? - El Forum - 12-17-2009

[eluser]Anthony Linton[/eluser]
Hi everyone,

I'm having trouble with my .htaccess file. Here it is as it stands.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ps3vs360/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php

This works fine.

My problem is that during development I'm working at http://localhost/ps3vs360/ and then deploying it to my production server at

Normally, this wouldn't be a problem. I could just set RewriteBase /ps3vs360/ on the local system and change it to RewriteBase / via FTP on the server. However, I've recently started using subversion which means the files must be identical on both my local server and the remote server or it'll moan at me.

You can see the problem if you go to, I get 500 Internal Server Error. I definitely have mod_rewrite enabled on the server etc so it is working ok, see here for my server settings: so it must be the RewriteBase.

Is there a way for me to check if it's localhost, and if so, use the directory /ps3vs360/ and if not use RewriteBase / ? I've googled for a solution to this and can't find one, and I suck at htaccess conditions.

Thank you Smile

mod_rewrite, conditional RewriteBase? - El Forum - 12-17-2009

Files dont have to be identical. Just add your local .htaccess to svn:ignore and it wont commit nor update...

mod_rewrite, conditional RewriteBase? - El Forum - 12-17-2009

[eluser]Anthony Linton[/eluser]
ah yes, I use beanstalk for deploying from the repository and apparently if I change the permissions on .htaccess on the remote server it'll just leave it. Thanks! Smile

mod_rewrite, conditional RewriteBase? - El Forum - 12-17-2009

Other way is to define local address for your project and use it as a vhost. That way structure would be the same always and you could have the same .htaccess file without rewritebase.

For example this ps3vs360 project you would define host and point it After that, add to your dev server's vhosts.

I use windows as development server with Wamp and heres the steps I make for a new project:

1. Create the directory for the project (D:\web\\public_html). I always put code outside of webroot so I create the public_html also on development server(and to have the exact same structure than on production webserver)

2. Open C:\WINDOWS\system32\drivers\etc\hosts
- add line:

3. Open vhosts file(I have it on C:\wamp\vhosts\vhosts.conf, which is included in the main httpd.conf) and add vhost:

<VirtualHost *:80>
    DocumentRoot "D:/web/"
    <Directory "D:/web/">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all

Done! Smile

mod_rewrite, conditional RewriteBase? - El Forum - 12-17-2009

[eluser]Anthony Linton[/eluser]
Cahva, the perfect solution!

I used a guide @ for XAMPP.

I can now browse to http://ps3vs360/ instead of http://localhost/ps3vs360/ and not have to mess around with sub-directory issues.

Thanks very much.

mod_rewrite, conditional RewriteBase? - El Forum - 12-18-2009

thank you very much lol Smile it's amazing