I defined the default_controller as "Home" in routes.php. When example.com is written as url, the page works. It also works when example.com/home is written as url. Could I show 404 error page when example.com/home is entered as url?
The other question is I have two functions in Home.php in controller folder. When I call a function such as contact, the url is seen like example.com/home/contact. Could I show the url such as example.com/contact instead of .com/home/contact?
This can all be done, with Routes.
Your first question;
"Could I show 404 error page when example.com/home is entered as url?"
$route['home'] = '404';
This would show a 404 page whenever someone tries to visit /home. If you visit / it would show the default controller.
The second question:
"Could I show the url such as example.com/contact instead of .com/home/contact?"
Again, this is pretty easy with Routes.
$route['contact'] = 'home/contact';
Anyone who visits /contact would see the home/contact method.
Hope this helps.
Related
I want to redirect user to the page that he has came from after serving a form and taking the input from that form upon successful submission he has to redirect to the same page.
I want this to be done in Golang.
Thanks in Advance
You can use
http.Redirect(w, r, r.Header.Get("Referer"), 302)
r.Header.Get("Referer") always contains the referring url for current page ( which is previous url)
Update
As you have said in comment that your are using same url for post and get. In that case it will be update the get url as your refer url.
In this situation you can pass the url as parameter so on success you can
redirect user to that url.
For example,
If, user gets redirect to the upload page from home page then make url like this,
http://example.com/upload?redir=http://example.com/home
So now you have knowladge from which page the user was landed this page
just redirect it to the redir url you got from url.
redirect_url = r.FormValue("redir)
http.Redirect(w, r, redirect_url , 302)
I am a beginner in codeigniter 3.1.2.
While I am running localhost//ci it shows 404 page not found error. ci is my folder name.
What should I do?
May be you gets 404 error because of Controller.
Defining a Default Controller
CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php file and set this variable:
$route['default_controller'] = 'blog';
Where ‘blog’ is the name of the controller class you want used. If you now load your main index.php file without specifying any URI segments you’ll see your “Hello World” message by default.
For more information, please refer to the “Reserved Routes” section of the URI Routing documentation.
or may be there .htaccess problem
check link for more https://www.sitepoint.com/community/t/404-page-not-found-the-page-you-requested-was-not-found-codeigniter-project/223800
i have a url which is working given below
Eg: (working)
www.domain.com/post-type/postname
www.domain.com/offer/get-free-20-rs
Now i want to replace that url
like this
Eg:- (unworking)
www.domain.com/brandname/postname
www.domain.com/paytm/get-free-20-rs
when i replaced the first url (www.domain.com/offer/get-free-20-rs )with second url (www.domain.com/paytm/get-free-20-rs ) then it goes to 404 error page.
Basically post_type replace with other post type name.
But i got this Url but problem is goes to 404 error page.
So how to resolve this problem.
Thanks
It seems you have no page on this url. It goes to 404 because there is no post or page against this page. You have to edit this page www.domain.com/offer/get-free-20-rs using the edit url options that is displayed on the post to this www.domain.com/paytm/get-free-20-rs
I'm working on a project in codeigniter. What I have done until now is that if you type for instance
http://localhost/ci_project/dashboard
it will redirect to a page called: restricted.
However, what I want to do is that when you type dashboard on the url, codeigniter will redirect to login controller. If the login is successfull, go to the dashboard or whatever controller that the user added into the URL.
Basically the idea is to get a variable from the URL given by the user.
Thanks a bunch!
You can use the redirect function to send your users to any page you like:
redirect($URL, 'refresh');
You can read more about this function here (at the bottom of the page:)
http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
Place an if statement in the target controller function (I'm assuming the index() function of the Dashboard class) to test if the user is logged in, then redirect as needed.
Hello all
I have a controller which calls a model which returns after a db query an array to my view which prints some json which i can see in my browser.The problem is that this page has a 404 status header for no reason.
Any suggestions?
A page that shouldn't exist is often sends a 404 header in CodeIgniter.
You could do one of the following
Check if you the controller/method exists
Check if you have any routing that may be pointing you to another controller/method
Check if that location can be browsed via a browser
If nothing works, it would be better if you posted some of your code, routing, etc that may help.