PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 7, 2022

[FIXED] How to redirect // in Laravel 5.7?

 March 07, 2022     .htaccess, laravel, laravel-5, php, redirect     No comments   

Issue

Older version of laravel here, 5.7. I have a situation where I have a url like this http://127.0.0.1:8000//

I have a catch all of this

Route::get('{uri}', ['uses'=>'PageController@render'])->where('uri', '(.*)');

The URL that comes into the render method is ''. I'm not quite sure the best way to take http://127.0.0.1:8000// and redirect that to http://127.0.0.1:8000.

.htaccess doesn't seem to let me redirect that either with Redirect 301 // / or RewriteRule ^$ /? [L,R=301]

Is there any way to get around this?

thanks!


Solution

They are treated as the same resource in the browser. Anyway you can check the request URI on the server and redirect to the root path like this:

Route::get('/', function () {

    // check the request URI
    if($_SERVER['REQUEST_URI'] !== '/')
    {
        return redirect('/');
    }

    # The rest of the code
    # ...
});


Answered By - Milad
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing