[英]How to Redirect non-existing data page to Page Not Found in Codeignitor?
[英]Redirect a non-existing url to error page
我想將所有不可用的鏈接重定向到error.php頁面
這就是我想要的
如果有人輸入了一個不存在的鏈接,那么我想將它們重定向到我的錯誤頁面而不是webhost的404錯誤頁面
www.example.com/wrong_page.php
應重定向到
www.example.com/error.php
您有2個選項可將錯誤的REQUEST_URI
重定向到錯誤頁面
1)內部重定向
您的Web服務器將在內部將錯誤的請求重定向到錯誤頁面,
在WebRoot/.htaccess
嘗試此操作
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /error.php [NC,L]
2)外部重定向
您的Web服務器將從外部將錯誤的請求重定向到錯誤頁面,
或者在WebRoot/.htaccess
嘗試此操作
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://example.com/error.php [R,NC,L]
重寫條件檢查請求的文件名是否不是目錄或文件,然后RewriteRule將其重定向到錯誤頁面。
您可以將此指令添加到.htaccess
文件中:
ErrorDocument 404 /error.php
有很多類型的錯誤頁面(只是谷歌)。 您可以使用.htaccess處理它們。 例如
ErrorDocument 500 /errordocs/500.html
ErrorDocument 404 /errordocs/404.html
ErrorDocument 401 /errordocs/401.html
ErrorDocument 403 /errordocs/403.html
您需要在.htaccess
文件中進行設置。 您可以使用.htaccess生成器或只是將此行添加到新的.htaccess文件中:
//Custom 404 errors
ErrorDocument 404 error.php
除了錯誤頁面,您可能還想禁用目錄列表或更改目錄的默認頁面。 盡管如此,還是使用了.htaccess文件。 如果您不熟悉它,只需使用我提到的鏈接即可。
這是我的.htaccess
<Files .htaccess>
order allow,deny
deny from all
</Files>
IndexIgnore */*
ErrorDocument 400 /err_400.php
ErrorDocument 401 /err_401.php
ErrorDocument 403 /err_403.php
ErrorDocument 404 /err_404.php
ErrorDocument 500 /err_500.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.