Redirect http requests to a new folder with apache rewrite rules

When you reorganize the structure of a website, you might want to redirect requests to files in a old folder to a new one without loosing the pagerank. In this example, I will redirect all requests from directory "olddir" to directory "newdir", so that requests like http://www.yourdomain.tld/olddir/page.htm get redirected to http://www.yourdomain.tld/newdir/page.htm without loosing the Google pagerank ... Read more

Redirect a subdomain with apache mod_rewrite and keep the URL in the address bar

If you want to redirect a subdomain like sub.domain.tld into a subdirectory of the website and keep the original URL in the browser location bar, you may use the following apache directives. RewriteEngine on RewriteCond %{HTTP_HOST} ^sub.domain.tld [NC] RewriteRule ^/(.*)$ /sub/$1 [L] This rewrite rule can be added into a .htaccess file in the website ... Read more

Redirect domains without www (e.g. to with apache rewrite rules

If all your visitors shall access your website with a URL like and not without www, use the following apache rewrite rule for redirecting them. RewriteEngine On RewriteCond %{HTTP_HOST} !^www RewriteRule (.*) http://www.%{HTTP_HOST}$1 [L,R] The apache rewrite rule can be added in a .htaccess file in the website root directory or if you use ... Read more