简体   繁体   中英

HTACCESS remove .php extension except for certain url

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?

Just add an extra condition:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM