htaccess redirect all reaquests code example

Example 1: redirect htaccess non www to www

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

Example 2: htaccess redirect to html page

RedirectMatch 301 ^/blog/about /blog/about.html

Example 3: htaccess route to index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L,QSA]


Using Sub directory:
RewriteRule ^.*$ /mvc/index.php [L,QSA]

Example 4: .htaccess force example

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Tags:

Html Example