htaccess – changing webroot folder

Ever wondered how to change the webroot of the web hosting package? Maybe you have two domains mapped to a single web hosting package, but you want both domains to act independently… Well you can with a .htaccess file in your public_html folder. Simply create a blank text file called “.htaccess” (if you don’t already have one) and add the following code:

# first domain
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?yourfirstdomain.com$
RewriteCond %{REQUEST_URI} !^/yourfirstdomain_folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourfirstdomain_folder/$1
RewriteCond %{HTTP_HOST} ^(www.)?yourfirstdomain.com$
RewriteRule ^(/)?$ yourfirstdomain_folder/index.php [L]

# second domain
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?yourseconddomain.com$
RewriteCond %{REQUEST_URI} !^/yourseconddomain_folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourseconddomain_folder/$1
RewriteCond %{HTTP_HOST} ^(www.)?yourseconddomain.com$
RewriteRule ^(/)?$ yourseconddomain_folder/index.php [L]

htaccess redirects

I find the best way to setup redirects of websites is to use the .htaccess file. It a plain text file which can help you get enhanced features on your website, one of them being 301 redirects. 301 redirects are used to redirect visitor’s URL requests if the URL has been permanently moved, and thus are great to let Google and other search engines know of structural changes and minimising the risk losing your ranking.

Here are some useful examples:

Domain Redirects

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

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

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

Automatically add “www” to your URLs

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

Sub Domain redirects

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

Switch to SSL URLs for specific folders

RewriteCond %{HTTPS} off
RewriteRule ^folder1(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^folder2(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect all contain in specific folder

redirectMatch 301 ^/foldername/ https://www.yoursite.com/newfolder/

How to view ZIP file contents on Mac without extracting files

Viewing the contents of a ZIP file on a Mac without extracting the ZIP content has been missing from the basic functionality available on a standard OS X installation. Now you can download a small freeware plug-in for ‘QuickLook’ which fixes this issue. Allowing you to view the contents before extracting the complete ZIP file.

View the developer’s website for the download and installation instruction. Tested on Mac OS X Snow Leopard.

http://d.hatena.ne.jp/t_trace/20071125/p2