Home > IT Architecture > Three types of 301 rewrite/redirect for apache httpd server

Three types of 301 rewrite/redirect for apache httpd server

October 4th, 2011

Type 1:Exact URL without any query parameters:
Type 2:Exact URL with any query parameters
Type 3:Exact URL plus query parameters and/or sub pages
www.doxer.org/portal/site/doxerorg/mydoxer/anyone / EVERYTHING AFTER THIS INCLUDED

For Type 1:
RewriteRule ^/portal/site/doxerorg/mydoxer/anyone$ http://www.doxer.org/shop/pc/anyone? [L,R=301,NC]
For Type 2:
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/portal/site/doxerorg/mydoxer/mydoxer/anyone/register$ http://www.doxer.org/shop/pc/anyone? [R=301,L,NC]
For Type 3:
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/portal/site/doxerorg/mydoxer/article http://www.doxer.org/mydoxer/latestnews? [R=301,L,NC]

1.In the destination URL, add '?' to the end if you don't want the query string to be auto-appended to the destination URL
2.[R] flag specifies a redirect, instead of the usual rewrite, [L] makes this the last rewrite rule to apply, [NC] means case insensitive

3. Don't forget to paste below between <Directory></Directory>:

AllowOverride All
Order allow,deny
Allow from all

4. To rewrite the whole site, you can set below in .htaccess:

RewriteEngine ON
RewriteRule ^(.*)$ http://newsite.example.com/$1 [R=301,L]

Good Luck!

Categories: IT Architecture Tags:
Comments are closed.