404 page redirection in codeigniter 3 |
hi i have developed website in codeigniter 3 but i am not able to redirect url where the data is not found in the database to 404 page. can any one help me out.
(12-10-2020, 07:51 AM)php_rocs Wrote: @shivaraj,hello @php_rocs i am using CodeIgniter 3.1.11 for website development but here i have done seo dynamic url rewrite from routes. i have connected to the database form routes and i have passed foreach loop to rewrite the normal url to seo friendly url in segments pattern. here everything is working fine if i try with wrong url i wont get any error instead it will loads the complete pages with blank content. i tried to redirect to 404 page by using if statement like. if the entry in not found in the database it should redirect the page to the 404 custom page which i created. but the problem i am facing is the if condition is working fine if the value i passed in the uri is found in the database table. if not found the database itself will not respond. nor it will not give any error. but i tried in all the ways by passing if condition even in SQLi query. but if try the query within the database i will get the result but if i pass the same query in the codeigniter i wont get any response from the database if the uri is wrong my website link is https://computer-repairs.in my contact no is +91 9980598215 can u help me to resolve the issue plz (12-11-2020, 06:57 AM)php_rocs Wrote: @shivaraj,once after connecting to the database $urilist = $this->uri->segment(2); $query = $this->db->query("SELECT name FROM tablename WHERE name = '$urilist' "); $result = $query->num_rows(); if ($result == 0 ){ header("Location: https://computer-repairs.in/404pagenotfound"); } i tried other method like $query = $this->db->query("SELECT COUNT(name) AS newresult FROM tablename WHERE name = '$urilist' "); $result = $query->result(); if ($result == 0 ){ header("Location: https://computer-repairs.in/404pagenotfound"); } but if i try with if condition like if ($result == 0 ){ echo 'page not found'; }else{ echo 'page found'; } if i type the right uri it is printing page found message but if i type the wrong uri it is not printing page not found message i am not getting why??????? but i tried with all the possible options to achieve this task. Ie with some more if conditions. do u have any suggestions. else if you can ping me when you are online i can show you through remotely my whatsapp contact no is +919980598215
@shivaraj,
Please show us the actual code. Where is the statement that executes the query? Also, have you tried determining what the result value is? Also, are you sure the your query is executing correctly? What does the final generated query look like when it is sent to the database? Your initial if condition should work just fine. What we need to do is make your results value consistent. That is the challenge.
[quote pid="382544" dateline="1607591986"]
Please I have similar issues, still trying to master this CodeIgniter thing, I built a website for Sports predictions https://bet9javip.com everything works fine, if a URL doesn't exist it simply simply loads the index page, but this is bad for SEO, i want the URL to change, please someone should help me on this [/quote] |
Welcome Guest, Not a member yet? Register Sign In |