Reputation: 1851
I want apache to rewrite everything to my index.php, meaning that apache should not process anything, it should ignore the url input and just forward it to the index.php.
I've searched for this many times, and the best solution I found was:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
But today I noticed that if I enter an existing path, apache will show the forbidden page and I don't want that. What I want is to always show the index.php whatever the uri is (obviously the part behind the domain name :P).
I'm using $_SERVER['REQUEST_URI']
to let PHP route everything, using a MVC app, so apache trying to process the url input is very conflicting.
I disabled the indexing, and I'm also thinking on denying access to the document root and allowing only the folder where the index.php is:
httpd.conf:
<Directory "/srv/http">
Options -Indexes +FollowSymLinks
AllowOverride None
Require all denied
</Directory>
vhost.conf:
<VirtualHost *:80>
ServerName example.com
#Redirect permanent / http://www.example.com/
DocumentRoot "/srv/http/example.com/www"
<Directory "/srv/http/example.com/www">
Require all granted
<Files "index.php">
SetHandler "proxy:unix:/run/php-fpm/www.example.sock|fcgi://localhost/"
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
</Directory>
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
</VirtualHost>
I even want to only allow access to the index.php file, but maybe this is overkill?
Moving Require all granted
inside the <Files>
block does not work, but this is secondary and you'd probably discourage me from trying (probably is not even possible, or necessary).
So, how can I prevent apache from processing the urls? To let my MVC app take care of the routing.
Upvotes: 1
Views: 94
Reputation:
Well the rewrite code you are using specifically excludes existing URLs, so just stop that. You don't need the RewriteBase
either.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule . index.php [L]
</IfModule>
If you need more, let me know, but looks like that should put you on the right track for what you're trying to achieve. Don't you have any image files, CSS and such you want Apache to serve itself? That's the usual reason for excluding existing URLs.
Upvotes: 1