Enable .htaccess in Apache on Mac OS X 10.5 (Leopard)

The default configuration of Apache on Mac OS X disables the use of per-directory configuration files (.htaccess). Enabling this feature requires a small number of changes in the the Apache configuration.

sudo pico /etc/apache2/httpd.conf

under the section:

<Directory "/Library/WebServer/Documents">

change AllowOverride None to

AllowOverride All

If you are using the Sites folder in your home directory, you should also change the AllowOverride in the configuration files for each user: /etc/apache2/users/*.conf

Share this post:
  • Digg
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • RSS

About Vlad

Comments

8 Responses to “Enable .htaccess in Apache on Mac OS X 10.5 (Leopard)”
  1. James S says:

    Thanks for this – very helpful!

  2. Musta says:

    First of all thanks a lot for this useful information to get started with the painlful world of htaccess. I have checked high and low for a solution to enable .htaccess files on my Macbook pro but in vain. I should also mention that I am using Mac ox 10.4.11 and not Leopard.
    Apart from the apache that is built in my machaine I have installed a Mamp server to have a local server for testing. Everything works fine but the problems arise when I tried to implement SEO friendly urls by using .htaccess files. When I include this latter in the root of my sites (MAMP/htdocs/Mysite/.htaccess) it does not work and cause the following error.
    [b]Internal Server Error[/b][i]
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator, you@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
    More information about this error may be available in the server error log.
    Apache/2.0.63 (Unix) PHP/5.3.2 DAV/2 Server at localhost Port 8888[/i]

    and in my Mamp apache log file I get the following error:
    [i][Tue Jun 01 09:46:40 2010] [alert] [client ::1] /Applications/MAMP/htdocs/Mysite/.htaccess: Invalid command ‘{\\rtf1\\mac\\ansicpg10000\\cocoartf824\\cocoasubrtf480′, perhaps mis-spelled or defined by a module not included in the server configuration, referer: http://localhost:8888/Mysite/index.php?DepartmentId=2&CategoryId=4&Page=4
    [/i]

    These are the errors that I always get even when inserting an empty .htaccess file. I have changed the AllowOverride line from None to All in both the Mamp and the httpd.conf that ships with the machine but in vain. I have also made sure that the following lines: [i]AccessFileName .htaccess[/i] and[i]LoadModule rewrite_module modules/mod_rewrite.so[/i] are uncommented but in vain. I just do not know wht is going wrong with my local testing server. I hope that you could help me ride of this nightmare that I have been fighting for more than 5 days.

    Any help would be greatly apreciated, And many thanks in advance

    • Vlad says:

      The answer to your problem is very simple: I presume you are trying to edit the .htaccess files with the built-in text editor on Mac, that’s TextEdit. Unfortunately for this simple operation, the default setting in TextEdit is to create new documents in RTF format, instead of plain text.

      So what I suggest is that you delete the previously created .htaccess files, open TextEdit, switch to plain text from Format menu > Make Plain Text or Cmd+Shift+T, add your content and save the .htaccess file.

      You can also set this as default setting for TextEdit using Preferences > New Document > select Plain Text.

      • Musta says:

        Hi Vlad, thanks for your quick reply. I have just followed your advice and at least I do not get the server internal error of apache. however I could not get the urls rewrite function through the following .htaccess file:

        # Enable mod_rewrite
        RewriteEngine On

        # Specify the folder in which the application resides.
        # Use / if the application is in the root.
        RewriteBase /mysite

        # Redirect URLs ending in /index.php or /index.html to /
        RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html?)\ HTTP
        RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,L]

        # Redirect category pages
        RewriteRule ^.*-d([0-9]+)/.*-c([0-9]+)/page-([0-9]+)/?$ index.php?DepartmentId=$1&CategoryId=$2&Page=$3 [L]
        RewriteRule ^.*-d([0-9]+)/.*-c([0-9]+)/?$ index.php?DepartmentId=$1&CategoryId=$2 [L]

        # Redirect department pages
        RewriteRule ^.*-d([0-9]+)/page-([0-9]+)/?$ index.php?DepartmentId=$1&Page=$2 [L]
        RewriteRule ^.*-d([0-9]+)/?$ index.php?DepartmentId=$1 [L]

        # Redirect subpages of the home page
        RewriteRule ^page-([0-9]+)/?$ index.php?Page=$1 [L]

        # Redirect product details pages
        RewriteRule ^.*-p([0-9]+)/?$ index.php?ProductId=$1 [L]

        instead When I checked the apache log file I get the following error.

        authentication …
        [Tue Jun 01 12:57:55 2010] [notice] Digest: done
        [Tue Jun 01 12:57:55 2010] [notice] Apache/2.0.63 (Unix) PHP/5.3.2 DAV/2 configured — resuming normal operations
        [Tue Jun 01 12:59:29 2010] [error] [client ::1] client denied by server configuration: /Applications/MAMP/htdocs/mysite/.htaccess

        I would be so happy if you could tell me what I am doing wrong here. Thanks a lot Vald

      • Vlad says:

        I am not sure what the problem is with your configuration as I have downloaded the latest copy of MAMP, installed it, created the .htaccess file with the content you provided and it works seemingly!

        Do you receive any error in your browser? What page are you redirected to and what message do you receive when you access a webpage like: http://localhost:8888/mysite/index.html?ProductId=232

      • Musta says:

        Hi Vld, it is me again I tried again with a fresh reinstall of MAMP. This time I didn’t get any error in my browser i get redirected to my navigation pages correctly but the urls rewrite just do not work. Instead of getting SEO friendly urls I only get the generated urls (like: http://localhost:8888/mysite/index.html?ProductId=232) with its variables in the navigator address bar. It is really weird, the newly created .htaccess files generate no errors but it just do no work. In my apache log file I get the following which I do not really know if it has to do with my problem.

        [Tue Jun 01 19:23:29 2010] [notice] caught SIGTERM, shutting down
        [Tue Jun 01 19:23:30 2010] [notice] Digest: generating secret for digest authentication …
        [Tue Jun 01 19:23:30 2010] [notice] Digest: done
        [Tue Jun 01 19:23:30 2010] [notice] Apache/2.0.63 (Unix) PHP/5.3.2 DAV/2 configured — resuming normal operations

        I am really disappointed with this since I could not keep on programming my application without enabling the Urls rewrite mod through .htaccess. And I am deeply sorry for losing your time.

  3. Vlad says:

    I think it would be better to continue this conversation over email. Please provide a working email address and we will communicate further there. The one you are currently posting for the comments does not appear to be valid.

  4. Musta says:

    Hi Vlad, finally it worked!
    It was just another silly mistake of mine. I just had to get ride of the .txt extention. That was all and thanks again for your time

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!