Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

Easy 301 or 302 redirect using .htaccess

Here is an easy way to redirect one url to another if you don't need any fancy regex pattern matching.

Permanent 301 redirect
Redirect permanent /relative_source_url http://full_destination_url/


-or-

Temporary 302 redirect
Redirect temporary /relative_source_url http://full_destination_url/

www to no-www, and vice-versa

To redirect requests for www.example.com to example.com (without the www) put this in your .htaccess:

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]


And to do the reverse (redirect non-www to www), try this:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed