convert original URL to friendly URL

You seem to be confused with how URLs and rewriting works. The notion that “I need to rewrite this2 to this1 “ means: Someone either enters this2 in their address bar or clicks on a this2 link. Server sees a request for this2 Server has a set of rules to internally rewrite the request from … Read more

.htaccess – how to force “www.” in a generic way?

I would use this rule: RewriteEngine On RewriteCond %{HTTP_HOST} !=”” RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] The first condition checks whether the Host value is not empty (in case of HTTP/1.0); the second checks whether the the Host value does not begin with www.; the third checks for HTTPS (%{HTTPS} … Read more

How does RewriteBase work in .htaccess

In my own words, after reading the docs and experimenting: You can use RewriteBase to provide a base for your rewrites. Consider this # invoke rewrite engine RewriteEngine On RewriteBase /~new/ # add trailing slash if missing rewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L] This is a real rule I used to ensure that URLs have a trailing … Read more

.htaccess redirect all pages to new domain

The below answer could potentially cause an infinite redirect loop… Here, this one redirects everything after the domain name on the URL to the exact same copy on the new domain URL: RewriteEngine on RewriteRule ^(.*)$ http://www.newdomain.com/ [R=301,L] www.example.net/somepage.html?var=foo redirects to: www.newdomain.com

Redirect non-www to www in .htaccess

Change your configuration to this (add a slash): RewriteCond %{HTTP_HOST} ^example.com$ [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L] Or the solution outlined below (proposed by @absiddiqueLive) will work for any domain: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] If you need to support http and https and preserve the protocol choice try the following: … Read more