- Instant help with your Developer coding problems

Redirect all requests to index.php using htaccess

Question:
How to redirect all requests to index.php using htaccess?
Answer:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|webp|ico|js|css)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php [L]
</IfModule>
Description:

To redirect all incoming requests to a specified target you can use the mod_rewrite module with the proper conditions and rules. It is a common use case in MVC frameworks, however, you probably want to redirect only URLs that don't point to static assets like images, stylesheets, or js files.

So to skip specific extension use RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|webp|ico|js|css)$

 

Share "How to redirect all requests to index.php using htaccess?"