1

Hello i'm using laravel 5 for my project.

i have routes like :

news/some-news-title/galery?page=2#photo/

it works great for my paginating galleries. But i saw that when i add extra parameter end of to url , it still works.

example :

news/some-news-title/galery?page=2/amp
news/some-news-title/galery?page=2/asdasd

normally it should not work. But it shows same gallery page.

i tried some codes , but it did not work for me :

Route::any('news/{any}/{any?}/amp', function(){
   return 'error';
});

Route::any('news/{any}/{any}/{any}', function(){
   return 'error';
});

when tried these codes , it still opens same page.

How can i block or redirect this parameters to 404 page ?

Thanks !

Crazy Coders
  • 133
  • 1
  • 12

1 Answers1

1

it works great for my paginating galleries. But i saw that when i add extra parameter end of to url , it still works.

It seems that it is the right behaviour .

Lets have a look at your URL

It may be something like http://example.com/news/some-news-title/galery?page=2#photo/anythingelse

I have checked it at http://www.freeformatter.com and it says :

enter image description here

Now Your are concerned about last part of url(Hash).

According to wikipedia :

The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document. It is typically used to identify a portion of that document.

In simple word you can't filter the Hash Part because it belongs to current document and treated as single and last portion of URL.

Rahul K Jha
  • 788
  • 9
  • 18
  • i want to filter last part after hash , is it same for last section of url ? `/anythingelse` part – Crazy Coders Oct 16 '16 at 09:23
  • for example : `/news/news-post-title/galery?page=7` is ok , but i can't block `/news/news-post-title/galery?page=7/asdasda` – Crazy Coders Oct 16 '16 at 09:27
  • In simple word browser doesn't send the hash part to server but you can use javascript to get last portion and then send that part by ajax to server. – Rahul K Jha Oct 16 '16 at 09:28
  • Have a look at http://stackoverflow.com/questions/940905/can-i-read-the-hash-portion-of-the-url-on-my-server-side-application-php-ruby and http://www.stoimen.com/blog/2009/04/15/read-the-anchor-part-of-the-url-with-php/ – Rahul K Jha Oct 16 '16 at 09:30
  • If you want to block "/asdasda" the you should move that portion out of Hash Part of URL. – Rahul K Jha Oct 16 '16 at 09:31
  • i will try it ! – Crazy Coders Oct 16 '16 at 09:32