Apache – mod_rewrite rules

Examples to configure rewrite rules in .htaccess file:

http://example.com/page.php

RewriteEngine On
RewriteRule ^demo/?$ /page.php [L,NC]


Rewrite localization url with $_GET[‘lang’] variable
http://example.com/english

RewriteEngine On
RewriteRule ^(.*)/$ /$1 [R=permanent]
RewriteRule ^([a-z]{2})$ /index.php?lang=$1


Redirect 301
http://www.example.com/ to http://example.com/

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