Reputation: 3923
I wrote this code to redirect everything to index.php.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA]
I want to somehow adjust !-f
to allow .php
files to be 301 redirected to /
without getting into a redirection loop. I have /foo/bar/218
that loads index.php
which requires view/foo_bar.php
. I want /view/foo_bar.php
to be inaccessible via the address bar.
Upvotes: 1
Views: 55
Reputation: 784998
You can try these rules:
# redirect .php requests to /
RewriteCond %{THE_REQUEST} \.php[\s?] [NC]
RewriteRule ^ / [L,R=302]
# existing rules without .php files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.php$ index.php [QSA]
Upvotes: 1