Add something new to Virb:

Virb

Are you sure you want to delete that?

or Cancel

 

So, recently I got sick of .htaccess and more specifically mod_rewrite not working locally, so I set out to figure out why. Why I wanted to do this is because as you know or should know. You should always work on your site locally and then publish them when ready, so there are no mistakes that happen on a production server.

This article is mostly for users on a Mac running Leopard, this also assumes you have changed your manifest/config.php to work locally.

So this problem turned out to be both hard and easy, the hard part was trying to figure everything out. The first thing we need to do is allow custom rewrite rules, so we need to edit our user httpd.cofig file. So if your using TextMate it would be something like this in the terminal.

mate /etc/apache2/users/username.conf

Replace username with your short user name on OS X. Next replace line 2 so it looks like this:

 
  Options Indexes MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
 

After you save that file, you will need to restart apache, this can be done in your System Preferences, under “Sharing” and then turn off and on again “Web Sharing” or use the command and type:

sudo apachectl restart

Now we just need to edit our .htaccess file in the root folder of our symphony install. If you have your copy in your Sites folder it will look similar to this:

### Symphony 2.0 - Do not edit ###

 
  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /~/mysite/

  ### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"
  RewriteCond %{REQUEST_FILENAME} favicon.ico [NC]
  RewriteRule .* - [S=14] 

  ### IMAGE RULES 
   RewriteRule ^image/3/([0-9]+)/([0-9]+)/([1-9])/([a-fA-f0-9]{3,6})(/(0|1))?/(.+).(jpg|gif|jpeg|png|bmp)$ /~/mysite/symphony/image.php?param=3:$1:$2:$3:$4:$6:$7.$8 [L]
   RewriteRule ^image/2/([0-9]+)/([0-9]+)/([1-9])(/(0|1))?/(.+).(jpg|gif|jpeg|png|bmp)$ /~/mysite/symphony/image.php?param=2:$1:$2:$3:0:$5:$6.$7 [L]
   RewriteRule ^image/1/([0-9]+)/([0-9]+)(/(0|1))?/(.+).(jpg|gif|jpeg|png|bmp)$ /~/mysite/symphony/image.php?param=1:$1:$2:0:0:$4:$5.$6 [L]
  RewriteRule ^image(/(0|1))?/(.+).(jpg|gif|jpeg|png|bmp)$ /~/mysite/symphony/image.php?param=0:0:0:0:0:$2:$3.$4 [L]

  ### CHECK FOR TRAILING SLASH - Will ignore files
  RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_URI} !/~/mysite$
   RewriteCond %{REQUEST_URI} !(.*)/$
   RewriteRule ^(.*)$ /~/mysite/$1/ [L,R=301]

  ### MAIN REWRITE - This will ignore directories
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)/$ /~/mysite/index.php?page=$1&%{QUERY_STRING} [L]

  

 DirectoryIndex index.php
  IndexIgnore *

######

Now be sure to add “Options +FollowSymLinks” to the top of your .htaccess file otherwise this wont work. After you follow these steps, you will now be able to view your site and sub directories of your site locally! I hope this article helps anyone who has been stuck like me.

Loading comments...

Likes

Details

Via Stephen Korecky

Viewed 36 times

© 2009 Stephen

virb.com/t/2028201
tweet!

Flag this text post!

Flag this text post as:

or Cancel

 

Advertisement

Flag this profile!

Flag this profile as:

or Cancel