【问题标题】:Laravel page redirection issueLaravel 页面重定向问题
【发布时间】:2020-09-01 17:09:09
【问题描述】:

您好,我是 laravel 初学者,在页面导航时遇到问题。

http://localhost/mylaravel/public/index

在索引页面中,我有几个项目,在 href 下方可以根据项目 ID 查看该项目的详细信息。*

<a href="{{route('singleitem',$product->id}}">
Route::get('/single/{id}', 'ProductController@single')->name('singleitem');
Route::get('/index', 'ProductController@index'); 

现在当我点击商品详情时,我会得到以下 URL,这没问题。

http://localhost/mylaravel/public/single/25T8C    (here id = 25T8C)

现在,当我单击主页时,它会从该页面添加单个 [single/index !!!] 的索引页面结尾

<a href="index" class="nav-link">Home</a>
http://localhost/laravel-test/mylaravel/public/single/index

我尝试添加斜线,但它被重定向到

<a href="/index" class="nav-link">Home</a>
http://localhost/index

这是我的 .htaccess

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

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

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

任何帮助将不胜感激。

【问题讨论】:

  • 你在用xammp/lamp吗???
  • 我正在使用 xammp
  • 是的,按照我的回答去做。如果答案有效,请标记为确认任何其他问题请评论

标签: php laravel .htaccess xampp


【解决方案1】:

直播时只需通过 /index

<a href="/index" class="nav-link">Home</a>

它会将你重定向到

http://yourdomain.com/index

但在本地主机上,您还必须添加目录名称(注意:在现场不会有文件夹名称。所以 /index 将在那里工作)。

<a href="/laravel-test/index" class="nav-link">Home</a>

或者,您必须通过 artisan 服务器运行 laravel,然后 /index 也将在您的 localhost 上运行。

您正面临这个问题,因为当我们在 URL 之前给出 / 时,它会将给定的 URL 与主机连接起来,而在 XAMPP 上,我们必须在 localhost 之后连接文件夹名称。

【讨论】:

  • 你是绝对正确的。两种解决方案都有效。非常感谢:)
猜你喜欢
  • 2021-11-19
  • 1970-01-01
  • 1970-01-01
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-18
相关资源
最近更新 更多