PHP : How to make my own 404 page not found error
- Make your own custom 404 page
- Make an .htaccess file and place it in your root
- Place this line inside the .htaccess file
ErrorDocument 404 http://www.example.com/your-custom-404.php
Read more here
How to create an error 404 page using PHP?
The up-to-date answer (as of PHP 5.4 or newer) for generating 404 pages is to use http_response_code
:
<?php
http_response_code(404);
include('my_404.php'); // provide your own HTML for the error page
die();
die()
is not strictly necessary, but it makes sure that you don't continue the normal execution.
Custom 404 Error Page in PHP
Create a .htaccess file and put the following line in it:
ErrorDocument 404 /errorpageFileName.php
That will set the page 'errorpageFileName.php to your error 404 page. You can of course change the file name to your likings.
You can read more in-depth about it here:
Custom 404 error issues with Apache
create a personalized 404 error page in php in localhost
You can create a .htaccess file in your localhost. Simply make sure it is in the root directory of your web server (I believe in WAMP, it's the www folder). In XAMPP, it's the htdocs folder
How to show custom 404 error page for the subfolder in php?
I don't know that whether it can work for you or not? But you can give it a try i think it can resolve your issue which is quite similar to the previously asked question on stack overflow htaccess 404 page redirect not working for sub directory path
brilliantly answered by @anubhava. I hope it can help you to solve the issue. Also if the above does not help you out then you can also visit this 2 links SOLVED "File not found." instead of custom 404 file with php-fpm enabled & SOLVED "File not found" appears instead of 404.shtml (easy htaccess solution)
Error 404 page in html with report function
Indeed, you want to use $_SERVER["REDIRECT_URI"]
.
I just looked up that sometimes I do this with htmlspecialchars(strip_tags(stripslashes($_SERVER["REQUEST_URI"])))
Note however that I suggest you use ErrorDocument 404 /404.php
(local instead of full url) for the redirection (or even use a single /error.php
for several status codes such as 401 and 403 and evaluate $_SERVER["REDIRECT_STATUS"]
)
How to redirect 404 error to 404.php page?
Try this in your .htaccess:
ErrorDocument 404 http://jobguide.australianenglishcenter.com/404/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ <YourRelativePathToPHPFile>/404.php [L]
Here,The ErrorDocument redirects all 404s to a specific URL
The Rewrite rules map that URL to your actual 404.php script. The RewriteCond regular expressions can be made more generic if you want, but I think you have to explicitly define all ErrorDocument codes you want to override.
NOTE: Replace
Related Topics
Facebook Graph API, How to Get Users Email
Posting Form Fields With Same Name Attribute
PHP: Storing 'Objects' Inside the $_Session
Create Programmatically a Woocommerce Product Variation With New Attribute Values
Ignore HTML Tags in Preg_Replace
How to Check What User PHP Is Running As
Why Is PHP Session_Destroy() Not Working
The MySQLi Extension Is Missing. Please Check Your PHP Configuration
How to Check If an Array Value Exists
How to Prevent Multiple Form Submission on Multiple Clicks in PHP
How to Create Helper Methods on Laravel Not a Facade
What Is the Meaning of Three Dots (...) in PHP
How to Set Proper Codeigniter Base Url
How to Add Custom Stock Status to Products in Woocommerce 4+
How to Get Video Duration, Dimension and Size in PHP
How to Round Up a Number to Nearest 10