How to Enable htaccess file in Mac OS X
How to Enable htaccess file in Mac OS X
Date posted : 10/01/2019
Introduction
Using your Mac for development of websites or web applications, is very easy as it already comes with Apache pre-installed in it.The problem is that .htaccess file does not work by default.
Steps to Enabling htaccess file in Mac Os X:
Initially we have to make changes in the main configuration file of Apache.
First some changes in the main configuration file of Apache.
sudo nano /etc/apache2/httpd.conf
The first thing I will do is to change the Document root from the default /Library/WebServer/Documents to my Sites folder under my home directory.
So, look for these lines:
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
And change them to:
DocumentRoot "/Users/your-username/htdocs"
<Directory "/Users/your-username/htdocs">
of course instead of your-username insert there your real username.
In the same file, under the section <Directory "/Users/your-username/htdocs">
look for:
- AllowOverride None
And change it to:
- AllowOverride All
Also edit this file:
And look for the same line AllowOverride None** and change it to *AllowOverride All
Step 1 :Add this Symlinks with appropriate ‘ – ‘ and ‘ + ‘ sign.
#</Directory>
<Directory /Users/Your-Username/htdocs>
Options -SymLinksIfOwnerMatch +FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
Step 2 :
The mod_rewrite.so
is loaded. Take away the commented ” # ” tag from the config file.
sudo nano /etc/apache2/httpd.conf
# Make sure below module "mod_rewrite.so" is loaded.
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so
#LoadModule perl_module libexec/apache2/mod_perl.so
LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so
Step 3:
Add Options +SymLinksIfOwnerMatch inside a htaccess file
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Options +SymLinksIfOwnerMatch
Step 4 :
Then restart apache:
sudo apachectl restart
You are now ready to put files to ~/htdocs/ folder and when you go to: http://localhost/ you will see those files appear, and if you add a .htaccess file, that is going to work.Thus the htaccess file is enabled in your mac os x.
Thank you! for using PHEONIX SOLUTIONS.
You find this tutorial helpful? Share with your friends to keep it alive.Be the first to comment, we value your suggestions. For further queries please comment below.
Thanks a lot this worked for me.