Point all requests to one PHP file

Apache: Point all requests to one PHP file

If you want every request to be routed through a main file (similar to how WordPress and a lot of frameworks do it) then you can use this code, and every request that isn't an existing file or directory (so users can still access .css or images):

  1. RewriteCond %{REQUEST_FILENAME} !-f
  2. RewriteCond %{REQUEST_FILENAME} !-d
  3. RewriteRule ^([^?]*)$ /index.php [NC,L,QSA]

Remember to create the /index.php file too.

Don't forget that you will probably need to enable the rewrite engine for these rules to work. Click the button below to find out how to do this.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about Point all requests to one PHP file

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Apache language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to find the 2nd most common item in an array?

How to exclude URLs from the Laravel CSRF protection?

How to Force www or non-www in htaccess

What is the max size, by default, of GET variables?

How to hide the server signature (hide Apache info) from HTTP headers with .htaccess

How to show a specific view file for certain error codes?

How to generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?

How to Extract Query String (from a URL) Into an Associative Array in PHP

What is the loop variable in a @foreach loop in Blade?

How to block an IP address in .htaccess