Say I have a website http://site.com. When a user surfs a non-existing page http://site.com/whatever.html, a default 404 page http://site.com/default.php is displayed.
How can I get what the user tried to surf? (get whateve.html in this case).
Is this a common feature?
Its in the Apache/Nginx error logs.
You can grep the file for 404
The answer might vary depending upon the server that you are using. For common servers like Apache & Nginx - if you type in http://site.com/whatever.html & if whatever.html doesn't exist then the content of 404 page (set in server configurations) will be displayed , but the URL location will be the same whatever.html.
If you want to pass parameters to your 404 page, you can try something like Regex to get your catched/matched value & pass it to 404 page, but I can't give you an exact answer since it depends upon which server you are using. Do let us know if this works or this is what you were looking for, will try to help more.
Using $_SERVER['REQUEST_URI'], you should get the filename the user requested.
Related
I'm encountering an issue where a user lands on a 404 page and then clicks a button to submit the 404 error they encountered. From there, they fill out a jotform (server config preventing simple form implementation from Wordpress or auxiliary plugins.)
The next step we'd like to take is to autopopulate the URL form field with the 404 error URL they encountered. Just some background info, we're operating the site through wordpress on a Windows box.
Is this possible? Seems unlikely, but I thought I'd ask and see what other developers might recommend.
(I'm aware of webmaster, analytics, and backend tracking of 404s. This was a specific setup requested for direct input from the user.)
[First time here, btw. Sorry in advance if I've broken any rules.]
In most cases, you can access the URL of the currently requested page via a PHP superglobal - $_SERVER["REQUEST_URI"].
This won't always be available to you, and there may be a Wordpress helper to get it without accessing the superglobal directly - but this should get you started.
Javascript is another simple option - window.location.href or similar will normally give you whatever is in the address bar.
Google has picked up around 30,000 404 URL's in Google Webmaster Tools and I've been manually redirecting a lot of them and using some regex/explode() to cope with some of them but I can't seem to make rules that cover it all.
When a 404 is about to occur I would like my 404 php script to check my table of existing urls for the closest match and redirect to it.
For example if the bad url is "http://www.example.com/category-somenonexistingpart-someactuallyexistingpart-somejibberish-1234.htm" I would like my database to return the existing url that resembles the bad url the most = "http://www.example.com/category-someactuallyexistingpart.htm"
Can this be done? Is it a good or bad idea?
First, create a 404.php page and have .htaccess redirect all 404's here. Then, using $_SERVER ( can't remember the specific key ), you can parse the requested URI, split it, then search the DB... you may notice an increased load on the DB, however.
I am creating an application in PHP.
One thing I want to do is make it so that if a user types in www.example.com/app/rrr.php where app is the main directory of my application and rrr.php does not exist, that either the program does not go anywhere or use ErrorDocuments in .htaccess to redirect back to the previous page. Thus far the only way I have been able to get this is to add this in my .htaccess:
ErrorDocument 404 C:\Users\Chris\Desktop\wamp\www\Master\errorcode.php
When I try to go to a page that does not exist (by typing in the address area), the program does not attempt to go to it. On a page that does exist (if I type in a php file that I have made) the program advances normally. My problem is that I doubt this will work for users who install it themselves, and I was wondering if anyone had ideas as to how to make this work for everyone.
Couln't understand your question fully, but what I think is,
You should direct user to 404 page where you will check if there is any referer then give a link along with 404 page something like You might want to go back, and if there is no referer just show 404 page.
How do I remove path inforation from a url?
For example in this url, http://stackoverflow.com/questions/ask, I want the user to only see http://stackoverflow.com. Is this possible to do?
I do a redirect in PHP from my root directory to path Foo. I don't want Foo to display in the URL.I also do a page reload of sorts using window.location.href = domain_name/foo. Similarly I don't want foo to display in the URL.
Is this possible to implment in Javascript or PHP or do I have to configure Apache to do this?
You cannot manipulate URLs in the browser's address bar using PHP or JavaScript. But you have guessed correctly, this is something that can be configured in Apache. For a primer on URL rewriting, take a look at this article.
I have seen websites that keep the user on the homepage and use AJAX to change the page content.
You should make yourself sober and then consider if you really want to hide anything and if your web site would work at all.
However, I can answer you already - it wouldn't.
We are using path information for the reason. And you'd better see it.
Read up on URL masking:
htaccess mask for my url
http://www.willmaster.com/library/web-development/URL-masking.php
etc... This cannot be handled in JS.
If you REALLY wanted to, you could do this in PHP: you would need to create an index.php page that was set up to handle the loading of other pages, and add a handler at the top of every page that detects the REQUEST_URI that sets any other link to redirect (header()) to the index page with the filepath stored in $_SESSION or another retrievable location. The index page would then render the requested page. However, this is ugly, wastes resources, and you're much better off with an apache level rewrite.
Someone had changed my .htaccess, and I have removed that.
But I still have phantom pages like this:
http://www.biztalk-training.com/?puqr=usoe
I don't have any 404.php, 404.shtml, or 404.html pages.
I checked CPanel for redirects on 404, and it looked empty (but would have created a 404.shtml if I filled it in).
If I type in something like this in the browser, I get a 404;
http://biztalk-training.com/anything.html
I'm looking for what to kill, remove or fix to get red of the phantom page. I'm a developer (other platforms) with moderate familiarity with PHP and CPanel sites. I'm used to seeing domainname.com/progname.php?parm=test and I know how that works. But I don't know how the ?puqr=usoe is producing content on my site. They have other pages similar discovered by doing a site: search on google.
Thanks,
Neal Walters
Have you checked your index page? Under normal circumstances, http://www.example.com/?foo=bar will pass the query string (?foo=bar) to the index of example.com and will not produce a 404.
If these malcontents got write access to your server - and it sounds like they did - they could have easily modified your index page.