简体   繁体   English

htaccess - 如果POST数据,不要重写URL

[英]htaccess - do not rewrite URL if POST data

I have read quite many responses about htaccess but it is still so confusing to me. 我已经阅读了很多关于htaccess的回复,但它仍然让我感到困惑。 I have the following rule in my .htaccess file, basically removing the .php extension from the files and resolving the extensionless URL's: 我的.htaccess文件中有以下规则,基本上从文件中删除.php扩展名并解析无扩展名URL:

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.example.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

However, when I want to contact eg contact_form.php (that handles processing of the form data from a form in HTML), it is being rewritten to contact_form and all the POST data is lost. 但是,当我想联系例如contact_form.php(处理来自HTML表单中的表单数据的处理)时,它将被重写为contact_form,并且所有POST数据都将丢失。 I would like to achieve that when the request contains post data, the URL should not be redirected/rewritten. 我希望在请求包含发布数据时实现这一点,不应重定向/重写URL。 I have honestly no idea how the rewrite rule should look like. 我真的不知道重写规则应该是怎样的。 All help greatly appreciated! 所有帮助非常感谢!

You can insert this rule as first rule to ignore POST requests: 您可以将此规则作为第一条规则插入以忽略POST请求:

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]

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

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