Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hassanshahzadaheer's avatar

redirecting URL problem

Hi please help me I am stuck in the URL problem I post a question but no one replay

I post it also on stack overflow please check the link

https://stackoverflow.com/questions/55365071/problem-with-redirect-to-other-pages-using-uri

0 likes
15 replies
richard's avatar

What backend framework are you using?

tokoiwesley's avatar

It's not clear whether this is related to Laravel. A clarification will help.

Ty's avatar

You need to provide more details to get assistance. Even on Stack Overflow they have asked you to provide more details and you haven't. So, with that being said,

• Are you using laravel? • What version of laravel? • Please post relevant code using code blocks example would be three back ticks before and after your code.

Snapey's avatar

Could it be because you have not set the document root correctly?

I don't know if the tutorial expects your routes to be in a sub folder.

Snapey's avatar

When you go to /LearnPHP/about then this works because it is adding about to /LearnPHP/

If you then have a link <a href="culture">Culture<a> then your browser thinks that culture is a sub resource of about so you end up with learnPHP/about/culture which clearly does not exist.

Because you are in a folder, you cannot have an absolute link of /about and /culture because / is also wrong since does not contain learnPHP

The answer is to serve learnPHP as the document root and to fix that, we need to know what web server you use.

hassanshahzadaheer's avatar

@SNAPEY - I use the Linux operating system, web server is Apache, xampp 7.1.26-0

PHP 7.2.15-0ubuntu0.18.04.2 (cli) (built: Mar 22 2019 17:05:14)

hassanshahzadaheer's avatar

@SNAPEY - Hi! snapey thanks for the help

maybe something goes wrong with

Request.php file

I try this

<?php
class Request
{
    public static function uri()
    {

      $uri = (substr($_SERVER['REQUEST_URI'],10));
      $removeSlash = rtrim($uri, '/');
      return var_dump($removeSlash);

    }
}

instead of this

<?php
class Request
{
    public static function uri()
    {
        return trim($_SERVER['REQUEST_URI'], '/');
    }
}

I replace the code because it was not working for me

thanks

Snapey's avatar

to follow the tutorial you need to set the document root

There is loads of info on the net how to do this

Please or to participate in this conversation.