Showing posts with label htaccess mod rewrite. Show all posts
Showing posts with label htaccess mod rewrite. Show all posts

Monday, June 11, 2012

redirect with WWW htaccess





If you need to redirect your domain name with "WWW" you can use the following htaccess code for Apache based web servers.


Redirect with WWW htaccess



Options +FollowSymLinks
RewriteEngine On

# Mention Domain name

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

# OR
# get domain name automatically.

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

Thursday, May 31, 2012

htaccess redirect with or without www


Developing SEO friendly website, you have to decide the domain name is whether it is with "WWW" or without "WWW". as per your need you can transform the user behavior by redirecting reversal order based on your need. If you decide without WWW mean, while user attempt to type with http://www.example.com you need to redirect http://example.com, If you decide with WWW mean, you need to redirect with www when user typing http://example.com to http://www.example.com

In this case, We have the great option in .htaccess to decide with or without WWW .
Here is the solutions for htaccess redirect with or without www

Examples with mentioning Domain Name

Redirect WWW to non-WWW or without WWW Domain Name:

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

Redirect non-WWW to with WWW Domain Name:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
Rewriterule ^(.*)$ http://www.example.com/$1 [R=301,NC]





Example with Suitable for any Website without mentioning the domain name:
(Suitable for any Website) no need to tell the domain name on code.

Redirect www to non-www (both: http + https)
if we need to do this for separate http and https:

Options +FollowSymLinks
RewriteEngine On

# if without https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# if https
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]


Redirect non-www to www (both: http + https)
if we need to do this for separate http and https:


Options +FollowSymLinks
RewriteEngine On

# if without https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# if https
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]




Wednesday, February 22, 2012

Directory Model URL Rewriting with htaccess and map content with php

Creating a dynamic content for web application, we need to consider the Search Engine Optimized web URL structure to main the quality of our web development says "SEO Friendly", Search Engines are clearly identified our web content if we have Directory Model URL structure in our websites. As a developer SEO Friendly URL is very important to any project. Let me explain How to create Directory Model URL Rewriting with htaccess and how to map your content with php.

.htaccess directory structure url rewriting



directory structure:

/index.php
/.htaccess
/include/home.php
/include/about_us.php
/include/contact_us.php