【发布时间】:2018-04-13 15:20:06
【问题描述】:
我正在尝试在 Laravel 中使用 GET 方法提交表单后重写 URL。我的 .htaccess 文件如下所示:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^/items/search/(.*)$ /items/search?m_id=%1 [QSA, L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
提交表单后,URL 仍如下所示:
http://127.0.0.1:8000/items/search?m_id=357
对此的任何帮助将不胜感激。
谢谢。
【问题讨论】:
-
“提交表单后,URL 仍然看起来像这样” - 你为什么会期待其他事情发生?这是浏览器如何提交 GET 表单。
-
不,为什么要这样?
http://127.0.0.1:8000/items/search?m_id=357是您提交表单时浏览器创建的请求 URL。而且您的重写不包含任何会以任何方式改变它的内容。 -
你要知道mod_rewrite不会重写输入,它只是重写访问路径。
-
是的,我想我现在理解得更好了。我确实看过这篇文章 hashbangcode.com/blog/using-modrewrite-form-parameters 也有帮助。
标签: php apache .htaccess mod-rewrite laravel-5.5