在laravel中自定义带有前缀的URL

问题描述:

我有这个html:

<ul>
   <li><a href="index.php/Page1">Page 01</a></   
   <li><a href="index.php/Page2">Page 02</a></li>
   <li><a href="index.php/Page3">Page 03</a></li>
</ul>  

如您所见,由于大学的服务器,我需要在所有链接中使用 index.php/前缀
(我无法更改).上面的方法已经完成,可以从首页直接转到任何页面都可以,但是如果我尝试从另一个页面访问页面,则会得到错误的URL并无法访问该页面:

As you can see, I need to use the index.php/prefix in all links due to the server of my university
(I can't change it). The way is done above, it works fine to go straightfoward from home to any page, but if I try to access a page from another page, I get a wrong URL and Can't access the page:

示例:

首页
http://localhost/php-project/public/

第1页(在家中)
来自: http://localhost/php-project/public/
收件人: http://localhost/php-project/public/index.php/Page1

第2页(在家中)
来自: http://localhost/php-project/public/
收件人: http://localhost/php-project/public/index.php/Page2

第1页(来自第2页)
来自: http://localhost/php-project/public/index.php/Page2
收件人: http://localhost/php-project/public/index.php/index.php/Page1

前缀会重复.我不知道该怎么做才能正常工作.

as you can see, the prefix repeats itself. I have no idea how to do it to work right.

有什么想法吗?

这是我解决问题的方式:

This is how I solved my problem:

  • 我在laravel的 helper.php
  • 上创建了一个辅助函数
  • I created a helper function on laravel's helper.php

函数custom_url($ routename){返回str_replace("index.php",",URL($ routename));}

并以此方式使用:

<ul>
     <li><a href="{{custom_url('index.php/Page1')}}">Importar Histórico</a></li>
     <li><a href="{{custom_url('index.php/Page2')}}">Alocar Disciplina</a></li>    
</ul>