Redirect rules of htaccess


If you want to redirect to http://domain.com to http://www.domain.com, check below rules.

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

~~~~~~~~~~~~~~~~~~~~~ O ~~~~~~~~~~~~~~~~~~~~~~~~~

Now if we open some folder and then we need to redirect to www check below rules

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

For example i want to open myfolder url and i have entered

http://domain.com/myfolder/

Our first url will not work in this time we need to create a new htaccess file and put into myfolder folder.

and then if you tried to open http://domain.com/myfolder/ it will be redirect to http://www.domain.com/myfolder/

Here some example of htaccess rules

RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?var1=$1 [L]
RewriteRule ^([a-zA-Z0-9]+)/([a-z]+)$ index.php?module=$1&var1=$2 [L]

RewriteRule ^([a-zA-Z0-9]+)/([A-Z0-9]+)$ index.php?var1=$1&var2=$2 [L]
RewriteRule ^([a-zA-Z0-9]+)/([A-Z0-9]+)/([a-z]+)$ index.php?var1=$1&var2=$2&var3=$3 [L]

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s