How to access the domain by custom name without changing actual url in next action

让人想犯罪 __ 提交于 2020-01-05 10:18:42

问题


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



来源:https://stackoverflow.com/questions/29294046/how-to-access-the-domain-by-custom-name-without-changing-actual-url-in-next-acti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!