How to properly use RewriteRule in Laravel 5.5 project?

时间:2018-02-01 18:33:52

标签: laravel .htaccess

This .htaccess is working only for http://localhost/ but I want http://localhost/portal:

RewriteEngine on
RewriteCond %{REQUEST_URI} !portal/public/
RewriteRule (.*) /portal/public/$1 [L]

url in browser is http://localhost/ , http://localhost/login and so on, when I changed it to:

RewriteEngine on
RewriteCond %{REQUEST_URI} !portal/public
RewriteRule /portal(.*) /portal/public/$1 [L]

url in browser is redirecting to http://localhost/portal/public/index.php instead of displaying http://localhost/portal/

1 个答案:

答案 0 :(得分:0)

如果您使用laravel,为什么不使用它的功能呢?

您可以通过Route Group Prefixes

来实现
Route::prefix('portal')->group(function () {
    Route::get('users', function () {
        // Matches The "/portal/users" URL
    });
});