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)$
Reference:
Apache mod_rewrite reference
Share "How to redirect all requests to index.php using htaccess?"
Related snippets:
- Setup HTTPS for local development on Windows 10
- Set default encoding to UTF-8 using Apache
- Enable compression in Apache using htaccess
- Cache static content using htaccess
- Redirect all requests to index.php using htaccess
- Set X-Frame-Options on Apache webservers
- Redirect www to non-www on Apache webservers
- Automatically redirect HTTP to HTTPS on Apache webservers
- Set X-Content-Type-Options in Apache
Tags:
redirect all requests, redirect requests htaccess, redirect, request, htaccess, apache Technical term:
Redirect all requests to index.php using htaccess