URL重写规则不起作用.我的URL在每次提交表单时都会附加到它自己


URL RewriteRule not working. My URL appending to itself with each form submission

我有一个主url:

http://localhost/alias

我有一个重写规则

Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

有这样的表格:

<form name="quick-search-form" action="test/action" method="POST">

每当我点击submit时,它都会一直放,每次多放一级(顺便说一句,没有测试/操作。这是为了测试表单标记是否返回到index.php?url=)。

http://localhost/alias/id/
http://localhost/alias/test/action/id
http://localhost/alias/test/action/test/action/id

更改为GET(几次之后):

http://localhost/alias/test/action/test/action/test/action/test/action/id?quick-search-select=student

我希望它进入http://localhost/alias/test/action(我的参数在后期数据中)。看起来它正在将新的"test/action"表单操作附加到URL的"id"部分。注意它是如何随着每次新提交而消失的。

页面实际上正转到正确的位置,这是默认的,因为没有测试控制器。但它一直把它放在URL的末尾。如果我放置一个现有的URL

为什么它会从表单标签中这样附加?如果重要,请使用IIS。

您在action属性中使用了一个相对url,因此实际路径是预先准备好的。

您必须设置一个基本路径,或者使用一个像/alias/test/action这样的绝对url。

要添加基本路径,您可以在html:的头部添加此路径

<base href="/alias/">