.htaccess文件访问特定文件的问题

时间:2016-05-07 05:47:00

标签: apache .htaccess mod-rewrite file-access

=> This is my folder structure

文件存在名称为deploy_email.php

这是我的.htaccess代码

<IfModule mod_rewrite.c>
RewriteEngine on
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm

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]
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]
</IfModule>

问题是我希望deploy_email.php文件可以使用扩展名进行访问,其余的文件扩展名应该被隐藏。

如果我在检查时使用上面的.htaccess代码,我发现deploy_mail.php无法获取数据,你可以在这里看到=&gt; This here

请提供一些解决方案。

1 个答案:

答案 0 :(得分:0)

使用R标志进行外部重定向时,POST数据会丢失。您应该跳过重定向规则中的所有POST个请求,而不仅仅是一个文件。

替换所有显示的代码:

RewriteEngine on

AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm

# redirect only all requests except POST
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(?:php|html?)[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

RewriteCond %{REQUEST_FILENAME}.htm -f
RewriteRule ^(.+?)/?$ $1.htm [L]

清除浏览器缓存并重新测试。