2014-03-12 04:38
浏览 90

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

I have read quite many responses about htaccess but it is still so confusing to me. I have the following rule in my .htaccess file, basically removing the .php extension from the files and resolving the extensionless URL's:

RewriteEngine On

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

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

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

However, when I want to contact e.g. 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. I would like to achieve that when the request contains post data, the URL should not be redirected/rewritten. I have honestly no idea how the rewrite rule should look like. All help greatly appreciated!

图片转代码服务由CSDN问答提供 功能建议

我已经阅读了很多关于htaccess的回复,但它仍然让我感到困惑。 我的.htaccess文件中有以下规则,基本上从文件中删除了.php扩展名并解析了无扩展名的URL:

  RewriteEngine On 
 #Nove directory, 删除尾部斜杠
RewriteRule ^([^ /] +)/ $$1 [R = 301,L] 
#重定向外部。  php请求无扩展url 
RewriteCond%{THE_REQUEST} ^(。+)\ .php([#?] [^ \] *)?\ HTTP / 
RewriteRule ^(。+)\。php $ http:// www / $ 1 [R = 301,L] 
#解析.php文件for extendedless php urls 
RewriteRule ^([^ /。] +)$ $ 1.php [L] 

但是,当我想联系时,例如 contact_form.php(处理来自HTML表单的表单数据的处理),它被重写为contact_form,所有POST数据都丢失了。 我希望在请求包含发布数据时实现这一点,不应重定向/重写URL。 我真的不知道重写规则应该是怎样的。 所有人都非常感谢!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpzbzp8728 2014-03-12 04:41

    You can insert this rule as first rule to ignore POST requests:

    RewriteCond %{REQUEST_METHOD} POST
    RewriteRule ^ - [L]
    解决 无用
    打赏 举报

相关推荐 更多相似问题