Htaccess Page Translation

Htaccess Page Translation

Use Google Translate to enable auto translation for foreign speakers to use your site. NOT CLOSE TO PERFECT but a nice feature with htaccess.

Step 1: Add language code to end of URL’s – for example this URL would be https://www.astralwebinc.com/htaccess_page_translation.php-he

Step 2: Add to htaccess file

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)-he$ http://www.google.com/translate_c?hl=he&sl=en&u=http://example.com/$1 [R,NC]
RewriteRule ^(.*)-fr$ http://www.google.com/translate_c?hl=fr&sl=en&u=http://example.com/$1 [R,NC]
RewriteRule ^(.*)-de$ http://www.google.com/translate_c?hl=de&sl=en&u=http://example.com/$1 [R,NC]
RewriteRule ^(.*)-es$ http://www.google.com/translate_c?hl=es&sl=en&u=http://example.com/$1 [R,NC]

301 Redirect www with Htaccess

301 Redirect Non-WWW to WWW URL’s with Htaccess

It is important to decide on a consistent URL formatting from the beginning of your site.

Place this at the top of your htaccess file. BE SURE TO REPLACE EXAMPLE.COM WITH YOUR DOMAIN ON LINE 2 & 3:

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

301 Redirect WWW to Non-WWW URL’s with Htaccess

It is important to decide on a consistent URL formatting from the beginning of your site.

Place this at the top of your htaccess file. BE SURE TO REPLACE EXAMPLE.COM WITH YOUR DOMAIN ON LINE 2 & 3:

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

NOTES…
* Htaccess redirects works only with linux and unix servers (not IIS)
* After completing redirect check at least two pages (homepage and sub-page) with our server header tool – Look for 301 redirect