How to access the domain by custom name without ch

2019-08-07 07:32发布

问题:

Here is my website

www.mywebsite.com/project

But i want to aceess it by the name

www.mywebsite.com/project/admin

and

www.mywebsite.com/project/user

The content is inside the project folder.

How can i do this ?

Here is the .htaccess i already have

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Note :

I am using laravel framework

回答1:

Since, you are using Laravel so you don't need to do anything with .htaccess as Mike Anthony mention above. You need to put a parameter into your route.

I guess you want to list all projects by user and you have already got project controller. if this correct you can see the example below.

Exameple

//add this code in /app/Http/routes.php
Route::get('project/{username}', function($username)
{
    $user = User::where('username', $username)->first();
    $projects = $user->projects()->get();
});

Note: From the example you need to create relationship between User Model and Project Model