How can I do a 301 redirect?
Understanding by using a image of a 'Control Flow Chart'
mod_rewrite_cheat_sheet
Apache Tutorial: .htaccess files
*Note: The other example is only to change one URL.
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.
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
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
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 [I]RewriteRule ^index.php$ http://www.domain.com/ [R=301,L][/I]
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.