.htaccess拒绝.php扩展,但无法触发AJAX请求


.htaccess to deny .php extension but unable to fire AJAX requests

我添加了。htaccess调整来拒绝所有对。php文件的请求,并在内部将所有非。php请求重定向到。php文件。

在我的LocalHost上一切正常,但在生产环境中文件上传脚本失败(我发现文件上传脚本使用JS/Ajax调用php文件,未加载)

我的。htaccess配置是:

RewriteEngine on
# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
# Return 404 if original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?'.php[? ].*$"
RewriteRule .* - [L,R=404]

, JS调用是:

<form class="dropzone" id="dropzoneForm" action="ads_upload"
                        enctype="multipart/form-data" method="post">
                        <div class="fallback">
                            <input name="file" type="file" multiple />
                        </div>
                    </form>

...............

 $.post("ads_upldDelete?fname=" + file.name);//up-deletefile.php

ads_upload.php和ads_upldDelete.php都存在于服务器中,但由于模式重写规则无法到达,我可以在模式重写中写入和例外吗?

您可以使用:

RewriteEngine on
# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
# Return 404 if original request is /foo/bar.php
RewriteCond %{REQUEST_URI} !ads_up(?:load|ldDelete)'.php$ [NC]
RewriteCond %{THE_REQUEST} "^[^ ]* .*?'.php[? ].*$"
RewriteRule .* - [L,R=404]

和使用ads_upload.phpads_upldDelete.php链接。