![](/img/trans.png)
[英]Laravel: How to set & fetch custom header while redirecting to get method route url
[英]How to rewrite an url and load the corresponding laravel's route without redirecting?
我需要重寫http://example.com:8/?123&x=abc
到http://example.com:8/lorem/ipsus/123/abc
沒有任何重定向。
我已經完成了這個規則:
RewriteCond %{SERVER_PORT} ^8$
RewriteCond %{QUERY_STRING} ^(\d+)&x=(.+)$
RewriteRule ^/?$ lorem/ipsus/%1/%2 [QSD,P]
但是Laravel處理錯誤的路線( /
)。 所以我試圖改變路線,但似乎Laravel無法處理查詢字符串路由:
Route::get('?{key}&x={value}', 'myController@store');
Route::get('{data}', 'myController@store')->where(
[
'data' => '\?\d+&x=.+'
]);
Route::get('lorem/ipsus/{key}/{value}', 'myController@store');
他們都沒有實際工作。
這是laravel .htaccess:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
我迷路了...任何幫助將不勝感激:)
我設法通過使用apache mod proxy(P標志)在虛擬主機而不是htaccess上添加我的自定義規則來實現:
<VirtualHost *:8>
[...]
RewriteEngine On
RewriteCond %{SERVER_PORT} ^8$
RewriteCond %{QUERY_STRING} ^(\d+)&x=(.+)$
RewriteRule ^/?$ lorem/ipsus/%1/%2 [QSD,P]
<Directory "/var/www">
AllowOverride All
</Directory>
</VirtualHost>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.