Revision: 11338
                            
                                                            
                                    
                                        
Updated Code
                                    
                                    
                                                    
                        at February 17, 2009 09:37 by troynt
                            
                            Updated Code
## no-www redirect
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
## www redirect
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
## multiple domain redirect
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
## trailing slash
## BE EXTRA CAREFUL WITH THIS ONE!
## POST REQUESTS WITHOUT TRAILING SLASH
## WILL BE IGNORED!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
                                
                            Revision: 11337
                            
                                                            
                                    
                                        
Updated Code
                                    
                                    
                                                    
                        at February 4, 2009 13:47 by troynt
                            
                            Updated Code
## no-www redirect
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
## www redirect
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
## trailing slash
## BE EXTRA CAREFUL WITH THIS ONE!
## POST REQUESTS WITHOUT TRAILING SLASH
## WILL BE IGNORED!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
                                
                            Revision: 11336
                            
                                                            
                                    
                                        
Initial Code
                                    
                                    
                                                            
                                    
                                        
Initial URL
                                    
                                    
                                
                                                            
                                    
                                        
Initial Description
                                    
                                    
                                                            
                                    
                                        
Initial Title
                                    
                                    
                                                            
                                    
                                        
Initial Tags
                                    
                                    
                                                            
                                    
                                        
Initial Language
                                    
                                    
                                                    
                        at February 2, 2009 11:07 by troynt
                            
                            Initial Code
## no-www redirect
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
## www redirect
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
## trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
                                Initial URL
Initial Description
Please, be careful with trailing slash rewrite as post requests without a trailing slash will be ignored. Be sure to test if you plan on using that one. Not compatible with Drupal.
Initial Title
Common .htaccess Rewrite Rules
Initial Tags
htaccess
Initial Language
Apache