Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSteve Jones
Java Web Development Techdegree Student 78 PointsAnyway to hide 404.php file from the not found urls?
I configure my htaccess file to redirect the not found links to my custom 404 page but is there any way to hide the custom 404 page URL through htaccess, like:
If someone landed on the wrong page for example domain.com/contact2.php, it redirects to my custom 404.php file, but I want the URL should be intact with the original URL like domain.com/contact2.php, instead of 404.php file?
I hope you guys understand.
4 Answers
Philip G
14,600 PointsHi Steve,
Have a look over there, i think it is what you are looking for:
http://stackoverflow.com/questions/24080919/display-custom-404-error-page-without-redirection-in-php
Best Regards, Philip
Steve Jones
Java Web Development Techdegree Student 78 PointsI am totally confused here, he is using some kind of lines here
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteRule index.html$ index.php [L]
RewriteRule service.html$ service.php [L]
RewriteRule ^([^/]*)\.html$ about.php?pid=$1 [L]
RewriteRule ^cont/([^/]*)\.html$ contact-inner.php?tid=$1 [L]
RewriteRule ^contact/([^/]*)/([^/]*)\.html$ contact-page.php?tid=$1&ona=$2 [L]
RewriteRule ^about/([^/]*)\.html$ about-inner.php?oid=$1 [L]
RewriteRule ^service/([^/]*)/([^/]*)\.html$ service-page.php?oid=$1&ona=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ error.php [L]
I am testing this on localhost root folder and it doesn't work, it shows me the Server Encounter error. Where i am doing wrong?
Philip G
14,600 PointsThis code is specific to the question over at stackoverflow, you just need to use that part:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ 404.php [L]
Steve Jones
Java Web Development Techdegree Student 78 PointsI have done the same way, but it is not hiding the URL.
Here is my code:
This is for removing extension (Working)
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*) $1.php [L]
This is my question (Not working, both code has been placed and now showing 500 server error)
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ 404.php [L]
I know the code I placed in the wrong way, can you help me out to fix this issue.
Philip G
14,600 PointsCould you maybe send me an URL and the whole .htaccess? There must be an error somewhere else
Steve Jones
Java Web Development Techdegree Student 78 PointsI am testing on localhost. Above line of code is exactly same as it is on my htaccess file - http://pastebin.com/W5iJFiBn