ethyreal Mobile Developer

Enable .htaccess redirects on Mac Server (tiger)

May 06 2008 - By George Webster

Redirecting old pages in an SEO friendly way is fairly simple however the Mac Server does not have .htaccess files enabled by default.

Since the Mac Server unlike the personal web service (apache) that ships with the standard OS X 10.4 the Tiger Server in designed to serve more then on site so a simple change to the main httpd.conf file will not help. In fact i believe the main httpd.conf file is already set to look for the .htaccess file by default.

So with that said you need to edit any sites you have already set up through your server admin.

In the terminal you need to find each .conf file for the sites you which to use your .htaccess on.

cd /etc/httpd/sites

Then list the files in the directory with:

ls

It should look something like this:

0000_any_80_YOUR_SITE_NAME_1.conf
0002_any_80_YOUR_SITE_NAME_2.conf
0003_any_80_YOUR_SITE_NAME_3.conf
httpd.conf
virtual_host_global.conf

Which files you need to edit is obviously based on which sites you want to enable .htaccess for.

To edit each, the easiest way (IMHO) is to use pico, a built in editor through the shell (basically the terminal).

sudo pico 0002_any_80_YOUR_SITE_NAME_2.conf

Scroll down and locate a line that reads:

AllowOverride None

This should be changed to:

AllowOverride ALL

Then to save and close simple press ctrl and x, enter y to override your changes.

Anytime you make changes to the main httpd.conf or any other .conf files on Apache you must restart the server to load the changes.

sudo apachectl restart

Now that that is done you can add .htaccess files to the root directory of your site.

On the mac any file with a "." in front of it is hidden so you will need to use the terminal to view/edit it.

Navigate to your web root:

cd /Library/WebServer/Documents

Then change to the directory of the site you which to add the .htaccess file to. (the Documents will be the root if you have not set up multiple sites)

You can list the contents of that directory to include any hidden files with:

ls -a

If you see a .htaccess file already you need to make sure not to override anything already inside the file.

You can edit or create a .htaccess file with the same command.

sudo pico .htaccess

If you have one already scroll down to the bottom of the file. Otherwise simple add the following to the first line.

Redirect 301 /oldfile.html http://www.yoursite.com/newfile.html

Alternatively you can redirect your entire site to a new location with the following:

Redirect 301 / http://www.yournewsite.com/

Close and save the pico editor as before and you should be able to load your old page and see it magically redirected right before your eyes!

Recent Posts

Categories

© 2012 ethyreal.com