Announcement

Collapse
No announcement yet.

How can I do a 301 redirect?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I do a 301 redirect?

    How can I do a 301 redirect?
    Ruleset Processing
    Now when mod_rewrite is triggered in these two API phases, it reads the configured rulesets from its configuration structure (which itself was either created on startup for per-server context or during the directory walk of the Apache kernel for per-directory context). Then the URL rewriting engine is started with the contained ruleset (one or more rules together with their conditions). The operation of the URL rewriting engine itself is exactly the same for both configuration contexts. Only the final result processing is different.

    The order of rules in the ruleset is important because the rewriting engine processes them in a special (and not very obvious) order. The rule is this: The rewriting engine loops through the ruleset rule by rule (RewriteRule directives) and when a particular rule matches it optionally loops through existing corresponding conditions (RewriteCond directives). For historical reasons the conditions are given first, and so the control flow is a little bit long-winded. -> Apache.org
    Understanding by using a image of a 'Control Flow Chart'
    Click image for larger version

Name:	mod_rewrite_img1.gif
Views:	1
Size:	6.9 KB
ID:	3704267
    mod_rewrite_cheat_sheet
    Apache Tutorial: .htaccess files

    *Note: The other example is only to change one URL.
    Code:
    #  Enables or disables runtime rewriting engine 
    RewriteEngine on
    Options +FollowSymlinks
    RewriteBase /
    #  Site has permanently moved to new domain
    #  old_domain.com to new_domain.com
    RewriteCond   %{HTTP_HOST}   ^www.old_domain.com$   [NC]
    RewriteRule   ^(.*)$   http://www.new_domain.com/$1   [R=301,L]
    or
    RewriteRule ^index.php$ http://www.domain.com/ [R=301,L]
    How to create a .htaccess file extention
    You do not need to download and or install any software or hardware product to create an htaccess file. Basically all you want to use is your default systems text editor program such as 'Notepad'

    The only difficult part in saving file with extension name .htaccess is that if your system can accept a no-name filename with a long string extension.
    ".htaccess"

    # Open text editor 'Notepad'
    # Add your mod_rewrite for redirection header code (301)
    # From 'text editor 'Notepad' Toolbar - File - Save As...
    # File name: ".htaccess" - Note: Use double quotes around all characters
    # Save as type: All Files
    # Click [Save]
    # Upload file to your files directory.

    If this does not work for your current P.C., then you can upload file using a FTP program as ".htaccess.txt" and then use FTP to rename.
    Last edited by Jose Amaral Rego; Wed 5th Dec '07, 7:25am. Reason: Did not have it turn on... or have it say to turn on.
Loading...
Working...
X