Reputation: 330
So I have the following .htaccess
file on my server which removes .php extension from all files, forces https and also removes www.:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
# remove www and turn on https in same rule
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
The problem is that I have an upload form for users to upload an image, so when they upload the images because the file gets redirects from /upload.php to just /upload it then becomes a GET request because of the redirect.
Is there any way I can stop this one file from removing the .php extension?
Upvotes: 1
Views: 43
Reputation: 1619
Just add an extra condition:
RewriteCond %{REQUEST_URI} !/upload\.php$
This condition will prevent your rules to be applied to your upload.php file.
Upvotes: 1