What to do when user edits and breaks the url? - php

I have a url structure that looks something like some_page.php?id=123 and I get the id for that page and that is good.
But sometimes users either edit the url, or one way or another there is no id.
What do people usually do in that case? Should I just redirect the person to a 404 page? Or should I return 404 from that page in case they want to correct the url? Or is 404 the right thing to do in that case?
Also, how do I tell where this user came from?
Thanks!!

404, and don't redirect. Show them a nice error page but always give them at least the chance to correct the URL.
Also, make sure to actually send the header('HTTP/1.1 404 Not Found');

The symfony framework provides some built-in methods for dealing with the exact scenario you are describing. So issuing a 404 is a good strategy. Another idea is to offer a suggestive search if the asset cannot be found. For example, instead of just rendering a 404, you could actually do something like:
Sorry we could not find the asset you were looking for, below are some suggestions to better guide your search:
Books (12)
CDs (13)
DVDs (37)
This way you increase the users time on site, which should translate to more advertising dollars.

Related

Joomla and K2 Soft404 errors

We are using Joomla for a public site and we are getting a ton of soft 404 errors that all look similar to
/?option=com_k2&view=itemlist&task=user&id=xxx
where xxx = some numeric id. Obviously this is some soft of spamming but how do I turn it off in Joomla/K2?
I'm not particularly Joomla oriented but this seems a task I should be able to accomplish if I can get an idea of "where" to fix the code. The page shows a warning instead of an error
Warning
JUser: :_load: Unable to load user with ID: 35414
so it seems the "page" is actually there but with no content. I'm guessing some internal handler is spitting this dynamic content out but I want to return 404 in this case. Any ideas would be appreciated.
I'm trying to understand the nature of your problem. What do you mean with "Soft 404" errors? Do you have 404 errors or not?
On my K2 websites, I have sometimes "visitors" who try to find holes in K2. I then have many, many accesses of the same page. These visitors try to post comments or somethings else on the articles or user profiles.
Is this a similar thing that is happening on your site?
Is there a (Joomla) user on your site with ID 35414? If not, you can be pretty sure that someone is trying to hack your site.
Is the URL always requested by the same user? You can find this in the log files of the Apache server. In such cases I add a "deny from" statement to my .htaccess file.
In case you seriously expect a K2 related issue, I would recommend to post the issue in the K2 forum. This forum is quite knowledgeable and JoomlaWorks makes a serious effort to bring good K2 customer support.

Why design for "404 not found" page needed? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I want to know the advantage of 404 Not Found page. Why should one create a design for that ? Why not just set 404 header and redirect it to the home page with a message something like "What do you want of the URL? Please just walk into the website".
I figured many websites have a special page for the purpose. But why ?
Regards
404 Not Found
The 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists. A 404 status code does not indicate whether this lack of representation is temporary or permanent; the 410 (Gone) status code is preferred over 404 if the origin server knows, presumably through some configurable means, that the condition is likely to be permanent.
Hypertext Transfer Protocol (HTTP/1.1), section 6.5.4
404 pages let users know that the page does not exist.
Many people will change the URL manually (for example, /pictures/page/1 to /pictures/page/2). If you redirect the user to the front page it will be confusing to them. What they expected to happen (either go to page 2 or get a "Page not found" error) will not happen; finding themselves on the front page is not useful.
The more important thing, however, is that users should ideally never see 404 pages. When they actually do see one, it should be very clear that the page does not exist. Redirecting them does not tell them that the page does not exist; it tells them that... it is the front page, which it should not be. It is confusing.
Another issue is that search engines may find it odd that a lot of your pages get redirected to your front page. It is not exactly how the internet is supposed to work, so they may actually penalize your website because of it.
If you want your users to have a good experience on your website then your 404 pages should attempt to help them find whatever they were looking for. Some things you can show the user are:
A search box. Google has custom search boxes you can put on your website, which only search your site. If making your own is too complicated then this is a good solution.
If you are able to do something like this, then showing the user content that may be similar to what they are looking for can be useful. Just make sure that it works reasonably well. For example if you cannot find anything similar then don't show random stuff -- it is not helpful.
The newest content on the page. This is especially useful if it is a blog, news site, or some other kind of website that frequently gets new content.
The most popular content. If the user is just browsing to pass the time then popular content may allow them to continue browsing without leaving your website.
A link to or showing a sitemap may also be useful if the website is small enough to summarise on one page.
...and so on. Just try to think of what would be helpful to the user.
A good custom 404 page will help people find the information they're looking for, as well as providing other helpful content and encouraging them to explore your site further.
Moreover if you do not make your own custom page, the server's 404 error will be displayed which would not go by the design of your website. There are also negative elements which would try to access the unauthorized pages, and keeping a check of the same will give a sense of secured website.
What if you go in a departmental store and looking for a soap which
actually is out of stock, but the store keeper just make you to start
again from the section. Isin't the message not available is a
better option? The same goes here
The idea of a 404 page is to tell the user that the file they were looking for wasn't found, or that the link they clicked on was broken.
Say you're running a news site and a user clicks on a link to an article on your site, but the article has been deleted. A 404 page makes it very clear to the user that the article is gone. If you just redirect them to your homepage, they might think a featured article on your page is the one they were linked to, or that they got redirected for no reason. They won't have any reason to think that what they were looking for no longer exists on your server.
So the purpose of a 404 page is to say "Hey, what you were looking for isn't here." If you want to get more fancy, you can even use a 410 error instead, which means "Hey, what you were looking for used to be here, but it's gone now."

URL Rewrite: multiple addresses per article

I have a Joomla! website with rewrite rules activated. My article URl is mysite.com/category/ID-alias.html. The only thing which is important (from this url) is the id, because when I can access the article with any text at "category" and any text at "alias".
Let's show a concrete example:
My article URL: mysite.com/flowers/15-begonia.html
I can access the same by changing category name and alias directly from url:
mysite.com/tralala/15-anything.html //Shows the same article as above.
Is this SEO? If one of my visitors want to destroy my website SEO, can he open my articles with different addresses (like above) and Google will say that articles are duplicated? Does Google knows when a visitor goes to a webpage to which link doesn't exists anywhere?
Hope my question is clear.
Thanks.
Google do a good job of deciding which is the "right" version of a page - it is worth watching this video to see how they handle this situation:
http://www.youtube.com/watch?v=mQZY7EmjbMA
Since these wrong URLs should not be linked to from anywhere, it is unlikely they will be indexed by mistake.
However, should they index the wrong version of a page, setting a sitemap with the right one will usually fix it.
A visitor could not harm your SEO with this knowledge. The worst they could do would be to provide good links to a non-indexed page, which would cause the wrong URL to be indexed. However, it would then be very easy for you to 301 redirect that page and turn their attempts at harm into an SEO benefit.
I personally think Joomla should look into adding the canonical tag, but if you want that currently, you must use an extension like this:
http://extensions.joomla.org/extensions/site-management/seo-a-metadata/url-canonicalization-/25795
(NB I have never used this extension so cannot guarantee its quality - the reviews are good, though)

Bingbot attempting to access non existent pages

I recently made some major changes to an ecommerce website that include url structure. The url to view a product is modified by .htaccess and contains a short product description that if changed will not affect the results on the page.
example: www.Example.com/staticFolder/non-deterministic-product-details/MODEL#.html
Now in the error log file I am seeing bingbot requesting pages like example.com/non-deterministic-product-details
Our sitemaps don't link to this page and I am not able to find any bad links on pages. Has anyone else had problems with bingbot doing this? I found another question that was locked for being random. Bingbot causing 404 errors. Is it more likely that I am doing something wrong? Should I avoid using psuedo directories in my .htaccess?
-Thanks
There's nothing requiring that spiders stick only to link-crawling. It's entirely possible it's guessing URLs which are similar to known ones in the hope that it'll find something.
At any rate, I wouldn't worry about it unless you know it's following a bad link. It's quite normal to get lots of requests for non-existent pages.

PHP what to do when records don't exist in the database

I'm querying the database for a single record that matches the id passed in a url segment www.site.com/post/24.
Suppose post 24 doesn't exist. What is a safe and seo compliant way to deal with database requests that aren't found?
Below is my current solution using a Codeigniter model:
function read_post($post_id) //argument is the value of the url segment
{
$user_id = $this->tank_auth->get_user_id();
$this->db->where('user_id', $user_id);
$this->db->where('post_id', $post_id);
$this->db->limit(1);
$query = $this->db->get('posts');
//check if record exists
if ($query->num_rows() > 0) //row is returned
{
return $query->row(); //passed to controller and view
}
else
{
show_404(); //generate 404 message
return FALSE; //------------------------or exit()?
}
}
Please share your own best method/opinions.
Show a 404 page (with the 404 HTTP status code). That's the correct way of doing it. Otherwise you will just pretend you have infinitely many pages without content.
Describe shortly on the 404 page that the content isn't there anymore. Then you may add links to other popular content on your web page. For the sake of the user it's encouraged to try to lead them forward from the 404 page to interesting content, but do this with links so the user can read the 404 message and choose what to do next.
If you have meaningful URLs with words in you may also extract the words and do some kind of search in your database. List the search results on the 404 page as well, under some heading like "You may be interested in...". If you are selling a product or service, don't hesitate to make the 404 page into a nice selling one!
I have a strong belief in that the best SEO is the one which is best for your visitors. It's all about keeping them on your web site, and not scaring them away. Make your web site as user-friendly as possible and make it easy to find all your interesting content. My answer above stems directly from that belief. Do The Right Thing according to the standards (the HTTP standard in this case) and at the same time try to catch the user with good content and services. This is most certainly also what's best for your company at large regarding sales.
SEO has nothing to do with your database.
SEO has to do with keywords, titles, descriptions, word frequency, outgoing links to pages in the same teritory as the article on the final rendered HTML document.
Also, you need SEO friendly links such as /beach-party-on-sunday/, /post/24 won't cut it.
Answer:
According to SEO sanity, and HTTP servers workings in general, if an URL does not exist at your website it is best to respond with a 404 HTTP status, instead of 200 success.
However, if you have an URL for which you wish to redirect users, use permament or temporary redirects depending on wether the URL will come back to life or not.
Just play it simple and to the rules, and you will be SEO friendly.
I redirect to the homepage. In this specific case, I would redirect to www.site.com/post.

Categories