Results tagged “mod_rewrite” from Mod Rewrite Tips and Tricks

Redirecting according to the language that a user has set is actually fairly easy. The most important thing to remember is to put the most specific first.

For example to set up site with Irish, French and English as the fallback/default:

RewriteEngine on
# Irish Users
RewriteCond %{HTTP:Accept-Language} ^ga [NC]
RewriteRule ^$ /ga/ [L,R=301]
# French Users
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
# Default Page
RewriteRule ^$ /en/main-page [L,R=301]
For a full list of languages, the best I've found is from Perl's I18N-LangTags module.

I would never claim to be an expert with Apache's mod_rewrite module, but I have come to use it over the years to perform a number of little tricks to make my life easier.

What's this site about?

Apache's mod_rewrite module and how to make use of it.

Who is it aimed at?

Webmasters of all skill levels.

Will these tips work with IIS?

By default no, but there are some 3rd party ISAPI modules for IIS that emulate some of mod_rewrite's functionality


If anyone knows of any cool tricks using mod_rewrite and would like to contribute just pop me an email to let me know!