questions about htaccess

Discussion in 'Web Design and Development' started by olup, Oct 4, 2012.

  1. macrumors 6502

    Oct 11, 2011
    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} ^[nc]
    RewriteRule ^(.*)$$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!
  2. macrumors 68000


    Dec 7, 2007
    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 ^(.*)$$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.
  3. thread starter macrumors 6502

    Oct 11, 2011
    thanks for your explanation, I will give it a try

Share This Page