Part of the EllisLab Network
   
 
.htaccess on Mac OS X
Posted: 06 December 2006 07:38 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  7
Joined  12-06-2006

I know mod_rewrite and .htaccess is a pretty common topic.  I have searched through the forums and haven’t found a solution to my problem.

Here’s my issue:
I have a fairly vanilla OS X setup, replacing Apple’s PHP4 with the Entropy.ch PHP 5.x module.

I do my development from the my ~/Sites/ directory which houses a number of my projects and I’d prefer to keep my CI projects there as well.  I’d also like to test rewriting my URLs locally so I can get a better grasp of the subject.

here’s the .htaccess file that I’m trying out:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase
/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ index.php/$1 [L]
</IfModule>

My index.php file is located in the site’s root directory ~/Sites/ci_test/ along with my .htaccess file.

Here’s the kicker:
I tried moving my entire “ci_test” folder into /Library/WebServer/Documents/ (OS X’s Apache root directory) and the same .htaccess file (rewrite rules) works fine.

Are there any other OS X users (or other *nix users for that matter) that have things setup this way that have any idea what might be causing this?

Thanks for your help,
Jake

Profile
 
 
Posted: 06 December 2006 07:41 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  265
Joined  03-26-2006

Ok, it’s a problem with your rewrite base….

Change it from

RewriteBase /


to:

RewriteBase ~/osxusername/

Because apache runs with user-based htdocs directories.

Let me know how that goes.

Elliot

 Signature 

Want a job in a cool web 2.0 company? - doof is recruiting!

Elliot Haughin CodeIgniter Blog | FilePanda - Free File Sharing | CodeIgniter CMS
Twitter | Flickr

Profile
 
 
Posted: 06 December 2006 08:25 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  68
Joined  04-11-2006

Another suggestion…..

I run the wonderful MAMP utility on MAC OSX and it runs like a dream, www.mamp.info. Can switch between PHP4 or 5 easily!! Has phpmyadmin already setup and it is FREE!!!

Anyway this works nicely in that setup.

RewriteEngine on
RewriteRule
^$ /index.php [L]
RewriteCond
$1 !^(index\.php|images|css|userfiles|javascript|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]


James

Profile
 
 
Posted: 06 December 2006 09:05 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  7
Joined  12-06-2006

@Elliot - Thanks for the suggestion,  I’ve tried modifying the RewriteBase to ~/jake/ as well as a number of variations including (~/jake/Sites/, ~/jake/Sites/ci_test/, etc.) without any luck.

@jamesnicol -  I’ll checkout MAMP, I remember reading about it in the past.  Ideally I’d like to figure out what is going on here though because my production server is also OS X and I’d like to be able to troubleshoot issues on that end if they arise.

Thanks,
Jake

Profile
 
 
Posted: 07 December 2006 12:15 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  7
Joined  12-06-2006

Alright, I’ve made a little bit of progress with this issue.

I found that the per-user httpd.conf files are located in the /etc/httpd/users directory there I found my file “jake.conf”

I modified my jake.conf file to look like this:

<Directory "/Users/jake/Sites/">
    
AllowOverride All
    Options Indexes MultiViews FollowSymLinks
    Order allow
,deny
    Allow from all
</Directory>

things are looking better now with one exception.  I needed to add “FollowSymLinks” to the Options directive, however, in doing so mod_rewrite attempts to locate my Code Igniter folder in my “DocumentRoot”.  The result is the rewrite looks like this:
/Library/WebServer/Documents/Users/jake/Sites/ci_test/index.php/controller

when it should read like this:
/Users/jake/Sites/ci_test/index.php/controller

Am I missing something? Any thoughts?
Thanks,
Jake

Profile
 
 
Posted: 07 December 2006 01:16 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  80
Joined  10-09-2006

There is my one, thats all I needed for it to work.

<Directory “/Users/myname/Sites/”>
  Options Indexes MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

And here is an example .htaccess that I just dump in my dir:

Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|style\.css|images|robots\.txt|coffee\.js)
RewriteRule ^(.*)$ /~myname/project/index.php/$1 [L]

So my urls are http://me.local/~myname/project/

 Signature 

http://www.totali.co.nz - Real IT
http://www.oscar.school.nz - Internet Filtering

Profile
 
 
Posted: 07 December 2006 01:26 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Avatar
Total Posts:  7
Joined  12-06-2006

Thanks HushPe,

That did the trick, I guess I need to read more about mod_rewrite.  I overlooked the fact that it was appending “index.php” to my defined DocumentRoot directory.  With this rule it explicitly says use my home directory as the base.  Works great!

Thanks,
Jake

Profile
 
 
Posted: 07 December 2006 05:55 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  265
Joined  03-26-2006

Ah, of course…. you don’t always need the rewrite base, it’ll do it per current directory.

Cool, we all learn something new smile

 Signature 

Want a job in a cool web 2.0 company? - doof is recruiting!

Elliot Haughin CodeIgniter Blog | FilePanda - Free File Sharing | CodeIgniter CMS
Twitter | Flickr

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66424 Total Logged-in Users: 33
Total Topics: 84779 Total Anonymous Users: 0
Total Replies: 454946 Total Guests: 233
Total Posts: 539725    
Members ( View Memberlist )