Websterz Technology Blog

Free tutorials, Tech News, Source codes, Tweaks and Tips.

Here is quick code for creating redirection for your web site:

Redirecting to www:

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

This will redirect all request from http://example.com to http://www.example.com

Redirecting to www with https:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

This will redirect all request to https://www.example.com

Access page with multiple names/urls (SEO trick):

# The page login.php will be accessible by http://example.com/login and http://example.com/login.php
RewriteEngine On
RewriteRule ^login login.php [L]

Pass querystring (GET) values to PHP page:

# This will send id (GET) value as 1 to page checkout.php where you can get it into script via $_REQUEST[‘id’]

RewriteEngine On
RewriteRule ^checkout/id checkout.php?id=1 [L]

Above codes can be used for basic SEO and URL rewriting/redirection.

Spread the love
See also  How to call SOAP api from PHP

Leave a Reply

Your email address will not be published. Required fields are marked *