+ 10
How to redirect 404 error to 404.php page?
I need help in php. If the user visits a page or directory that does not exist, I would like the browser to redirect to: http://jully.com/pages/404/ I had created 404 page. and .htaccess file but this is not working. 404.php <?php echo "Page not found!"; ?> .htaccess ErrorDocument 404 http://jully.com/pages/404/ RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/404/$ RewriteRule ^(.*)$ pages/404.php [L]
5 Réponses
+ 9
.htaccess file (in root directory)
ErrorDocument 404 http://jully.com/404/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /pages/404.php [L]
If a 404-Request comes in, the "ErrorDocument" will redirect the request to "http://jully.com/404".
At this page, a rewrite rule and condition is implemented.
that means, that if the condition matches the current request, the rule gets applied.
^(.*)$
^ --> startsWith
( --> Open Group
. --> AnyCharacter
* --> one or more (Any character, at least one or more)
) --> Close Group
$ --> End of String
The "L" Flag at the end of the rules means "Last". It causes the mod_rewrite (the actual rewrite engine) to stop proccessing the rule set.
Means: Everytime the user gets redirected to "http://jully.com/404", the htaccess will rewrite the URL and redirect to http://jully.com/pages/404.php
+ 5
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
+ 5
Thanks all, I have solved it.
+ 3
.htaccess
ErrorDocument 404 /pages/404.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ pages/404.php [L]
0
I need help