1

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?

1
  • 1
    … or you could just make your form submit to the correct URL to begin with. Commented Nov 1, 2019 at 13:10

1 Answer 1

1

Just add an extra condition:

RewriteCond %{REQUEST_URI} !/upload\.php$

This condition will prevent your rules to be applied to your upload.php file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.