本文介绍了mod_rewrite的是preventing我提交表单的期望的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个www.example.com和m.example.com。该m.example.com所在的htdocs / M /文件夹内。我使用的.htaccess也删除的.php的扩展。我的根目录具有以下codeS:

I have created a www.example.com and m.example.com. The m.example.com resides inside the htdocs/m/ folder. I am also deleting the '.php' extensions using .htaccess. I am having the below codes on the root directory:

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

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

#mobile
RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteRule ^(.*)$ m/$1 [L]

# Resolve .php file for extension-less php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

我有形式的m.example.com。例如,在m.example.com/myform.php,我有

I have forms in the m.example.com. For example in m.example.com/myform.php, I have

<form method="post" action="processform.php">
 .....
</form>

我希望它被提交给M /文件夹(/m/processform.php),但现在它总是向主目录的processform.php。我曾尝试行动=// m.example.com/processform.php,但没有运气。

任何人都知道逑解决呢?谢谢!

Anyone know kow to solve it? Thanks!

更新:如果窗体的方法得到的,而不是后,表单将被正确提交(以/m/processform.php)

Update:if the method of the form is get instead of post, the form will be submitted correctly (to /m/processform.php)

推荐答案

所有重写规则其实你的规则是跳过 POST 请求。你可以调整规则,跳过 POST 从外部重定向,并保持内部重写主动/启用 POST 是这样的:

Actually your rules are skipping POST requests from all rewrite rules. You can tweak the rules to skip POST from external redirects and keep internal rewrites active/enabled for POST like this:

# Redirect external .php requests to extensionless url
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

#mobile
RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
RewriteRule ^((?!m/).*)$ m/$1 [L,NC]

# Resolve .php file for extension-less php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

PS:我还简化你的第二个规则

PS: I have also simplified your 2nd rule.

这篇关于mod_rewrite的是preventing我提交表单的期望的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 15:51