mod_rewrite laravel使用表单get方法

时间:2017-11-01 10:21:20

标签: php apache .htaccess mod-rewrite laravel-5.5

我试图在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>

提交表单后,网址仍然如下所示:

http://127.0.0.1:8000/items/search?m_id=357

对此有任何帮助将不胜感激。

感谢。

1 个答案:

答案 0 :(得分:1)

我只是回过头来看看这个。最后我使用了javascript的onsubmit函数来重写URL

onsubmit="window.location.href=this.action + '/' + encodeURIComponent(this.elements['m_id'].value); return false;"