如何来访问自定义名称的域,而无需改变实际的URL中的下一个动作自定义、实际、名称、动作

2023-09-02 09:55:40 作者:旧人旧事旧时光

下面是我的网站

www.mywebsite.com/project

不过,我想通过这个名字来aceess它

But i want to aceess it by the name

www.mywebsite.com/project/admin

www.mywebsite.com/project/user

含量为项目文件夹内。

我怎样才能做到这一点?

How can i do this ?

下面是的.htaccess 我已经有

<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]

注意:

我使用laravel框架

I am using laravel framework

推荐答案

既然,你正在使用Laravel,所以你不需要做任何事情的.htaccess麦克安东尼上面提到的。你需要把参数传入你的路线。

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

 
精彩推荐
图片推荐