简体   繁体   English

HTACCESS remove.php 扩展,除了某些 url

[英]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.:因此,我的服务器上有以下.htaccess文件,它从所有文件中删除了 .php 扩展名,强制 https 并删除 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.问题是我有一个上传表单供用户上传图像,所以当他们上传图像时,因为文件从 /upload.php 重定向到 /upload 它然后因为重定向而变成 GET 请求。

Is there any way I can stop this one file from removing the.php extension?有什么办法可以阻止这个文件删除 .php 扩展名?

Just add an extra condition:只需添加一个额外的条件:

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

This condition will prevent your rules to be applied to your upload.php file.这种情况将阻止您的规则应用于您的 upload.php 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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