Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Thread Tools Search this Thread Display Modes
Old Oct 4, 2012, 03:35 AM   #1
macrumors regular
Join Date: Oct 2011
questions about htaccess

I'm a total newbie, when it comes to htaccess files and I have a few questions about htaccess files. I would for a start like to accomplish two things:
a) redirect to a page without www. b) get the custom 404 html page working

I have fiddled around with htaccess and read a bunch of tutorials, however I've always gotten a 500 internal server error, when uploading the htaccess file in the root of my provider's server and I would like to know why that is.
From what I understand is that you upload the htaccess file to the root of the server, which would be www/public_html of my domain folder or do I have to change the directory to www/mydomain/public_html?
Anyway so this is what I got so far:

//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com[nc]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]

//Custom 404 errors
ErrorDocument 404 www/public_html/404.html (the 404.html is in the root folder of the server along with the other html pages)

Thanks in advance for your advice and help!
olup is offline   0 Reply With Quote
Old Oct 4, 2012, 10:48 AM   #2
macrumors 68000
SrWebDeveloper's Avatar
Join Date: Dec 2007
Location: Alexandria, VA, USA
If you want to affect all files/folders recursively for your site:

Upload it to the doc root (not root) meaning the folder Apache is set to look in for the base directory of your web site. If your web site is working fine, use PHP to examine the value of $_SERVER['DOCUMENT_ROOT'].

Otherwise place it in a specific folder to affect only that folder and its children.

.htaccess does nothing more than override settings in the Apache config file for folders and any children. Warning - some CMS's like Drupal already have .htaccess with necessary rules -- unwise to modify as its distributed with core updates and might be overridden so update Apache config or virtual host setup instead, otherwise either append and remember to re-add after updating or update Apache config if possible.

Any mistake will result in internal server error- these things are usually tested on a sandbox, never prod directly. FYI.

As to re-writing so www is enforced for any path:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.com$ 
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
As to 404:

ErrorDocument 404 /path/to/404page.html
The path is relative to the document root (not root as in "/" top level dir).

So try those, edit to use your domain, adjust path to be relative to doc root and you should be ok.
Jim Goldbloom
Sr. Web Developer, owner GoldTechPro, LLC
SrWebDeveloper is offline   0 Reply With Quote
Old Oct 6, 2012, 07:02 AM   #3
Thread Starter
macrumors regular
Join Date: Oct 2011
thanks for your explanation, I will give it a try
olup is offline   0 Reply With Quote

MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: htaccess cannot get to work! OS X Lion crittle1 Mac OS X Server, Xserve, and Networking 4 Jan 5, 2015 05:30 PM
October 2013 Event - Questions, questions eladnova OS X 5 Oct 9, 2013 06:40 AM
Can anyone help with .htaccess? msjones Web Design and Development 3 Jul 11, 2013 05:58 PM
Switch to Mac - questions, questions bscrabble iMac 8 Apr 1, 2013 09:30 PM
Enabling .htaccess for localhost octane OS X 10.8 Mountain Lion 3 Jan 24, 2013 09:04 AM

Forum Jump

All times are GMT -5. The time now is 03:10 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC