Welcome Guest, Not a member yet? Register   Sign In
mod_rewrite, conditional RewriteBase?

[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 http://ps3vs360.com/

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 http://ps3vs360.com/quiz/, 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: http://ps3vs360.com/phpinfo.php 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

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

[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

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 local.ps3vs360.com and point it After that, add local.ps3vs360.com 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\testproject.com\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: local.testproject.com

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/testproject.com/public_html"
    ServerName local.testproject.com
    <Directory "D:/web/testproject.com">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all

Done! Smile

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

I used a guide @ http://maff.ailoo.net/2008/07/set-up-mul...r-windows/ 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.

thank you very much lol Smile it's amazing

Theme © iAndrew 2016 - Forum software by © MyBB