简体   繁体   中英

404 Error handling with $_SERVER['REQUEST_URI']

I use different languages for my site. So the structure is quiet simple:

root / => 404.php
       => template_404.php

root/subdir/ =>(language_xy)404.php 

In my htaccess files I use a redirect to 404.php in case a page could not be found.

In that 404.php I use $_SERVER['REQUEST_URI'] to get the entered address that will be echoed to the user.

Depending from the default browser language the 404.php will be redirect to its subdir folder with the language files.

So it goes like that:

wrong URL entered => redirect to 404.php => reading out URL and default languages => redirect to language direction (language_xy)404.php => loading template_404.php from root and echo out wrong URL.

Now the problem is that I would like to have clean URL's like example.com/langauge_xy/(language_xy)404.php . Thats why I dont would like to use $_GET to send the entered URL to the (language_xy)404.php . I thought I could save the entered URL into a SESSION on 404.php and simply echo out on template_404.php . The first time this works but when reloading the page for some reason the content of the SESSION has changed. I have no clue why this happens. The $_SESSION['url'] is just used once.

So if there is someone who can give me hints on how to solve this issue I really would appreciate.

Thanks alot.

You could do it like this, or you could create a language file and with one 404.php file you could serve up different content based on the language in the session.

Find the users language: detect user language in PHP - stable solution

Language switching: Am I breaking any "php good practice" in the following php array which deals with 3 (human) languages?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM