Results 1 to 2 of 2
  1. #1
    Newbie
    Join Date
    January 18th, 2005
    Posts
    3,219
    Getting questions about how to redirect so here is the info!

    http://www.javascriptkit.com/howto/htaccess.shtml
    Comprehensive guide to .htaccess

    Tutorial written and contributed by Feyd, moderator of the JK Forum. Please see tutorial footnote for additional/bio info on author.

    I am sure that most of you have heard of htaccess, if just vaguely, and that you may think you have a fair idea of what can be done with an htaccess file. You are more than likely mistaken about that, however. Regardless, even if you have never heard of htaccess and what it can do for you, the intention of this tutorial is to get you two moving along nicely together.

    If you have heard of htaccess, chances are that it has been in relation to implementing custom error pages or password protected directories. But there is much more available to you through the marvelously simple .htaccess file.

    A Few General Ideas
    An htaccess file is a simple ASCII file, such as you would create through a text editor like NotePad or SimpleText. Many people seem to have some confusion over the naming convention for the file, so let me get that out of the way.

    .htaccess is the file extension. It is not file.htaccess or somepage.htaccess, it is simply named .htaccess

    In order to create the file, open up a text editor and save an empty page as .htaccess (or type in one character, as some editors will not let you save an empty page). Chances are that your editor will append its default file extension to the name (ex: for Notepad it would call the file .htaccess.txt). You need to remove the .txt (or other) file extension in order to get yourself htaccessing--yes, I know that isn't a word, but it sounds keen, don't it? You can do this by right clicking on the file and renaming it by removing anything that doesn't say .htaccess. You can also rename it via telnet or your ftp program, and you should be familiar enough with one of those so as not to need explaining.

    htaccess files must be uploaded as ASCII mode, not BINARY. You may need to CHMOD the htaccess file to 644 or (RW-R--R--). This makes the file usable by the server, but prevents it from being read by a browser, which can seriously compromise your security. (For example, if you have password protected directories, if a browser can read the htaccess file, then they can get the location of the authentication file and then reverse engineer the list to get full access to any portion that you previously had protected. There are different ways to prevent this, one being to place all your authentication files above the root directory so that they are not www accessible, and the other is through an htaccess series of commands that prevents itself from being accessed by a browser, more on that later)

    Most commands in htaccess are meant to be placed on one line only, so if you use a text editor that uses word-wrap, make sure it is disabled or it might throw in a few characters that annoy Apache to no end, although Apache is typically very forgiving of malformed content in an htaccess file.

    htaccess is an Apache thing, not an NT thing. There are similar capabilities for NT servers, though in my professional experience and personal opinion, NT's ability in these areas is severely handicapped. But that's not what we're here for.

    htaccess files affect the directory they are placed in and all sub-directories, that is an htaccess file located in your root directory (yoursite.com) would affect yoursite.com/content, yoursite.com/content/contents, etc. It is important to note that this can be prevented (if, for example, you did not want certain htaccess commands to affect a specific directory) by placing a new htaccess file within the directory you don't want affected with certain changes, and removing the specific command(s) from the new htaccess file that you do not want affecting this directory. In short, the nearest htaccess file to the current directory is treated as the htaccess file. If the nearest htaccess file is your global htaccess located in your root, then it affects every single directory in your entire site.

    Before you go off and plant htaccess everywhere, read through this and make sure you don't do anything redundant, since it is possible to cause an infinite loop of redirects or errors if you place something weird in the htaccess.

    Also...some sites do not allow use of htaccess files, since depending on what they are doing, they can slow down a server overloaded with domains if they are all using htaccess files. I can't stress this enough: You need to make sure you are allowed to use htaccess before you actually use it. Some things that htaccess can do can compromise a server configuration that has been specifically setup by the admin, so don't get in trouble.
    Now, onto the tasty morsels...

    -Tutorial Introduction
    -Error Documents
    -Password protection
    -Enabling SSI via htaccess
    -Deny users by IP
    -Change your default directory page
    -Redirects
    -Prevent viewing of htaccess
    -Adding MIME types
    -Preventing hot linking of your images
    -Preventing directory listing
    -Conclusion and more information

    Redirects

    Ever go through the nightmare of changing significantly portions of your site, then having to deal with the problem of people finding their way from the old pages to the new? It can be nasty. There are different ways of redirecting pages, through http-equiv, javascript or any of the server-side languages. And then you can do it through htaccess, which is probably the most effective, considering the minimal amount of work required to do it.

    htaccess uses redirect to look for any request for a specific page (or a non-specific location, though this can cause infinite loops) and if it finds that request, it forwards it to a new page you have specified:

    Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html
    Note that there are 3 parts to that, which should all be on one line : the Redirect command, the location of the file/directory you want redirected relative to the root of your site (/olddirectory/oldfile.html = yoursite.com/olddirectory/oldfile.html) and the full URL of the location you want that request sent to. Each of the 3 is separated by a single space, but all on one line. You can also redirect an entire directory by simple using Redirect /olddirectory http://yoursite.com/newdirectory/

    Using this method, you can redirect any number of pages no matter what you do to your directory structure. It is the fastest method that is a global affect.


    http://www.javascriptkit.com/howto/htaccess.shtml

    [This message was edited by SandraR on August 10, 2003 at 04:14 AM.]

  2. #2
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    Hi Sandra,

    Thanks for the redirecting post. I did not know that using .htaccess files can assure that your old pages still work with SE's while redirected to your new page. Very cool.

    And if it might help anyone else, an .htaccess file can also be used to parse .html files. This saved me alot of time with one of my old websites.

    Thanks again Sandra!

    Ian Lee, M.Sc.

    Internet Marketing Strategist / Affiliate Manager
    EYI, Inc.
    ilee_NO_SPAM@eyi.us
    http://www.eyiproducts.com
    604-596-9766

    Personal Sites: ADS-Links.com | HealthCastle.com

  3. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Redirects
    By PSU4Life in forum Newbie Affiliate FAQs & Helpful Articles
    Replies: 5
    Last Post: December 8th, 2006, 03:59 PM
  2. I need help on redirects
    By Airstrip in forum Programming / Datafeeds / Tools
    Replies: 7
    Last Post: May 20th, 2005, 11:02 PM
  3. Replies: 2
    Last Post: February 1st, 2002, 12:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •