Floris
31st October 2007, 10:50 AM
Tip of the day : How can I do a 301 redirect?
Original thread (http://www.vbulletin.com/forum/showthread.php?t=247241&goto=newpost) posted on vBulletin.com by : Jose Amaral Rego on : Wed, 31 Oct 2007 04:08:18 GMT
How can I do a 301 redirect?]How can I do a 301 redirect?
Quote:
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 (http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html)
Understanding by using a image of a 'Control Flow Chart'
Attachment 24198 (http://www.vbulletin.com/forum/attachment.php?attachmentid=24198)
mod_rewrite_cheat_sheet (http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.pdf)
Apache Tutorial: .htaccess files (http://httpd.apache.org/docs/1.3/howto/htaccess.html)
*Note: The other example is only to change one URL.
Code:
# Site has permanently moved to new domain
# domain.com to domain2.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.
Attached Images http://www.vbulletin.com/forum/images/attach/gif.gif mod_rewrite_img1.gif (http://www.vbulletin.com/forum/attachment.php?attachmentid=24198&d=1193799847) (6.9 KB)
vBulletin-Fans.com hopes you learned something from this great tip and if you also have a great tip you can submit it on vBulletin-Tutorials.com here (http://www.vbulletin-tutorials.com/newthread.php?do=newthread&f=591), or on vBulletin.com here (http://www.vbulletin.com/forum/forumdisplay.php?f=109). Don't forget to subscribe to this forum (http://www.vbulletin-tutorials.com/subscription.php?do=addsubscription&f=591) to get daily tips on how to best secure, optimize, manage and operate your vBulletin powered forum.
Floris & Staff
vBulletin Fans Network
http://www.vBulletin-Tutorials.com/
Original thread (http://www.vbulletin.com/forum/showthread.php?t=247241&goto=newpost) posted on vBulletin.com by : Jose Amaral Rego on : Wed, 31 Oct 2007 04:08:18 GMT
How can I do a 301 redirect?]How can I do a 301 redirect?
Quote:
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 (http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html)
Understanding by using a image of a 'Control Flow Chart'
Attachment 24198 (http://www.vbulletin.com/forum/attachment.php?attachmentid=24198)
mod_rewrite_cheat_sheet (http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.pdf)
Apache Tutorial: .htaccess files (http://httpd.apache.org/docs/1.3/howto/htaccess.html)
*Note: The other example is only to change one URL.
Code:
# Site has permanently moved to new domain
# domain.com to domain2.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.
Attached Images http://www.vbulletin.com/forum/images/attach/gif.gif mod_rewrite_img1.gif (http://www.vbulletin.com/forum/attachment.php?attachmentid=24198&d=1193799847) (6.9 KB)
vBulletin-Fans.com hopes you learned something from this great tip and if you also have a great tip you can submit it on vBulletin-Tutorials.com here (http://www.vbulletin-tutorials.com/newthread.php?do=newthread&f=591), or on vBulletin.com here (http://www.vbulletin.com/forum/forumdisplay.php?f=109). Don't forget to subscribe to this forum (http://www.vbulletin-tutorials.com/subscription.php?do=addsubscription&f=591) to get daily tips on how to best secure, optimize, manage and operate your vBulletin powered forum.
Floris & Staff
vBulletin Fans Network
http://www.vBulletin-Tutorials.com/