如何從php中製作的404自定義頁面獲取用戶嘗試訪問的鏈接 (How to get the link that the user tried to visit, from a 404 custom page made in php)


問題描述

如何從php中製作的404自定義頁面獲取用戶嘗試訪問的鏈接 (How to get the link that the user tried to visit, from a 404 custom page made in php)

我有一個不同語言的網站,因此我想為每種語言顯示一個自定義的 404 頁面。

有沒有辦法找出用戶嘗試訪問的頁面(沒有存在)以便找出我應該顯示 404 頁面的語言?

Web 服務器是 Apache。非常感謝。


參考解法

方法 1:

if you use .htaccess file for redirect then add

ErrorDocument 404 /yourdir/error/404page.php

then use request uri in session which stores the page user are visiting i.e.

$_SESSION['req_uri'] = $_SERVER['REQUEST_URI'];

then redirect user to $_SESSION['req_uri']. where $_SESSION['req_uri'] is the page user trying to access.

(by dasenAjay Makwana)

參考文件

  1. How to get the link that the user tried to visit, from a 404 custom page made in php (CC BY‑SA 2.5/3.0/4.0)

#http-status-code-404 #multilingual #PHP






相關問題

PHP在simplexml print_r上返回頁面錯誤 (PHP returning page error on simplexml print_r)

Apache Camel 和 CXF:多個 cxf:rsServer 標籤 .. 這可能嗎? (Apache Camel and CXF: Mutlitple cxf:rsServer tags .. is this possible?)

Penyiapan situs MSM 5 dengan pengalihan halaman 404 umum (MSM 5 site setup with a common 404 page redirect)

Успадкоўванне кантролера ASP.NET MVC 4 (ASP.NET MVC 4 controller inheritance)

Laravel Put Route Giving 404 錯誤 (Laravel Put Route Giving 404 Error)

WordPress 404 頁 (Wordpress 404 PAGE)

Gửi email tự động khi tải trang (Send Email Automatically On Page Load)

何時顯示“未找到記錄”頁面或返回 HTTP 404? (When to display "Record Not Found" Page or return HTTP 404?)

Breeze.js:處理空結果 (Breeze.js: Handling empty results)

如何從php中製作的404自定義頁面獲取用戶嘗試訪問的鏈接 (How to get the link that the user tried to visit, from a 404 custom page made in php)

Flask 文件上傳失敗並出現 404 錯誤 (Flask File Upload fails with 404 error)

如何在 ASP.NET 頁面中對超鏈接和內容進行變基? (How do you rebase hyperlinks and content in an ASP.NET page?)







留言討論