Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess rewriterule not working correct on mac

I have a website project on my mac book pro leopard, and I am using built in apache2 and php. I've made my configurations in both httpd.conf and user.conf to use htaccess. Changes done like :

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

<Directory >
    AllowOverride All
</Directory>

The problem is when i want to open a site like localhost/~username/site/site/index.php/welcome, index.php does some operations and finds the right controller and the right page.

But when I try to enter site like site/welcome apache gives me the following error :

Not Found

The requested URL Users/username/Sites/site/index.php/welcome was not found on this server.

The problem is apache gets this like it is indeed a file and the error statement gives it in a file system way, but this request must be fetched to index.php instead.

my .htaccess file looks like this

<ifModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>

What bothers me that this configuration works on both Linux and Windows but does not work on Mac. I feel doomed : )

like image 613
LostMohican Avatar asked Oct 29 '11 21:10

LostMohican


People also ask

Why is my .htaccess file not working?

Improper syntax being used It is quite common for a syntax error to be the reason for an . htaccess file not working. If you are familiar with how to read and configure . htaccess rules, double check your configuration.


2 Answers

I met the same problem too! 'DocumentRoot' doesn't work for me in Lion.

But this works:

RewriteEngine On

RewriteBase /~username/YOURPath

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
like image 198
tong Avatar answered Oct 13 '22 23:10

tong


On Mac OSX Mountain Lion, make sure AllowOverride is set to All on Directory /

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>

and root directory of your document root path:

<Directory "/Library/WebServer/Documents">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

also make sure that FollowSymLinks is included in Options.

if your "index.php-less pretty URL" is not on your DocumentRoot then add the following RewriteBase directory on your .htaccess file where your index.php exists, like the following example:

RewriteBase /~username/site/site/

If you would like to change the .htaccess file name to something else like .acl or htaccess.txt, uncomment the following line on your httpd.conf

# Various default settings
Include /private/etc/apache2/extra/httpd-default.conf

and change .htaccess in AccessFileName directive to anything you like in extra/httpd-default.conf file. For example if you would like to change .htaccess file to htaccess.txt change it to:

AccessFileName htaccess.txt

save them, restart your apache web server on OSX Mountain Lion, and hope you are good to go. Hope this helps.

like image 30
Aryo Avatar answered Oct 13 '22 23:10

Aryo