Rewrite Rules (7)


apache rewriterule: rewrite url to hash

After building a new website for a client, i needed to redirect their old URLs to new ones, normally a trivial task. But in this case the new site is driven by hash urls, so we need to rewrite url to hash url, such as: from: /apage to domain.co.uk/#!/area/section/bit and variations on that. By default […]

Read more...



creating html snapshots for google

A recent project required that we use hash navigation for speedy access to content, this also eeded to be indexed well, and seo’d up to the eyeballs, and so i set aboutand creating html snapshots for google. After reading, becoming daunted and almost put off, i realised that its actually a very simple process indeed! […]

Read more...



force a trailing slash

add a trailing slash to all URLs. [code]RewriteCond %{REQUEST_URI} /+[^\.]+$ RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L][/code]

Read more...



using get variables

This example changes /product.php?product_id=909 to /product?id=909 [code]RewriteCond %{QUERY_STRING} product_id=(.*) RewriteRule ^product.php(.*) /product?id=%1[/code]

Read more...



remove www.

remove the www. [code]RewriteCond %{HTTP_HOST} !^domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301][/code]

Read more...



remove trailing slash

[code]RewriteCond %{REQUEST_FILENAME}.php -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.php [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ /$1 [R=301,L][/code]

Read more...



force www.

making sure all urls are beginning with the www. [code]RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L][/code]

Read more...