I have a problem redirecting 404 errors to custom template.
My site structure is: project folder containing laravel and angularjs folders:
-> Project
-> AngularTheme
-> Laravel
In my .htaccess I have redirected the requests coming from / to /AngularTheme/index.php which is working fine.
RewriteRule ^(/)?$ ./AngularTheme/index.php [L]
Now, when anyone type in anything after the / i.e /foo it throws 404 not found error to which I am not being able to handle.
Inside laravel and Angular, there is not any problem redirecting to custome page.
Thanks for any help.
I would stick to what you know to do this.
here's a guide to do custom 404 handling in laravel
Though you can also play around in angular with routing to go to a specific page in certain cases.
Related
I have a simple SLIM application that responds to all requests to sent it in an API-like way for example the following url:
http://example.com/pages/subdirectory/slimApp.php/products
As you can see, the url to the slim app is absolute and pretty long but I have tried using Apache2 mod_rewrite to shorten the url as shown below
RewriteEngine on
RewriteBase /pages/
RewriteRule ^slimApp/(.*) subdirectory/slimApp.php/$1 [L,NC]
The code above rewrites to the main route of the app which is basically a 404 error page and acts like no request has been specified. When I access the app with an absolute url, it works as normal but if I try to access /products from the shorten url version, it fails with a slim 404 page.
Basically what I need is to translate the following and still be able to handle requests like shortened_url/products, shortened_url/something_else, etc. For-example:
http://example.com/pages/subdirectory/slimApp.php/products
to
http://example.com/slimApp/products
Bear in mind that /products is dynamic, any help is greatly appreciated.
I am developing a project in which I want to show my custom error page for 404 error. The codes that I have used are working but not totally. So at first, I am showing the structure for my project then the problems I have.
My site name is www.example.com in which I have 4 files and a folder, files are index.php, about.php, error.php, .htaccess and folder name is admin.
In the admin folder I have lots of pages that I am loading with one single page in index.php. the URLs to access any page I am doing it with www.example.com/admin/index.php?page=login like this, so when page is login it shows me the login page.
Up to this everything is good, now I have used a code in .htaccess
ErrorDocument 404 /error.php
So after using it when I am trying to access a wrong URL such as www.example.com/abt.php it shows me the code written in error.php which is quite natural for my code.
So when I am trying to access again two wrong URLs like www.example.com/adminindex.php?page=login and www.example.com/admin/inx.php?page=login it is not showing me the code written in error.php rather it shows me just a message File Not Found.
I want that these two types of wrong URLs it should show me the code written in error.php.
Interestingly what I want is easily happens in localhost but not on in server.
I cannot understand why it is working perfectly fine in localhost but not on the server.
So how can I do that please help me to complete it?
I don't know that whether it can work for you or not? But you can give it a try i think it can resolve your issue which is quite similar to the previously asked question on stack overflow htaccess 404 page redirect not working for sub directory path
brilliantly answered by #anubhava. I hope it can help you to solve the issue. Also if the above does not help you out then you can also visit this 2 links SOLVED "File not found." instead of custom 404 file with php-fpm enabled & SOLVED "File not found" appears instead of 404.shtml (easy htaccess solution)
In fact there is no good method for that without using mod_rewrite.
The only solution would be to put another .htaccess to your /admin subdirectory (with a valid path for your error.php)
in httpd.conf file (the is in AppServ\Apache24\conf directory)
put this
ErrorDocument 404 /error.php
if not be ok try save the file as html
I have a magento website, that is currently operating. Within a subfolder of this site, I have placed a 3rd party application that also has its own HTACCESS file to handle routing for its application.
When I access the folder http://example.com/somefolder the screen I expect shows up, but when I navigate to http://example.com/somefolder/newroute, I instead land on a magento 404 screen.
I have traced this to the magento htaccess file, in all cases, unlesss the path physically exists the rewriterule will always send the request to the index.php - this explains why Im getting there.
To fix this issue, I wrote a little rewriterule which I placed in the htaccess file of the magento store. The goal was to add an exception to any request that came through and contained any reference to my subfolder. The thought is now it should hit the path its supposed, then hit the htaccess file, and then route me to where IM supposed to be in this other application. Unfortunately it doesnt seem to work, after adding the rule I end up the same place - magento.
Here is what I've written:
RewriteRule ^(.*somefolder.*)$ $1 [L]
Im not sure what could be going wrong, as I think the approach seems pretty straight forward. Any ideas on how to remedy this situation?
Thanks.
Here is Your Simple Answer.Also Used By me on my site.
RewriteCond %{REQUEST_URI} !^/(yourfoldernameHERE)$
I have a Laravel 5 project with routes set up as well as a custom 404 page (mostly for missing/incorrect "pages").
So basically if I open any existing route I get the correct output and every other URL is showing the 404:
project.com/login - Fine, login page
project.com/ghdkfgl - 404
This looks clear and seems to be working as expected. So anything I add after the slash opens either an actual existing page or a 404 page.
Unless I put a 'index.php' anywhere in the URL. In this case, Laravel is executing the request for some reason like this:
project.com/jhdfkds/index.php/login - Opens the login page (the CSS and other resources are gone because of the paths but that's clear).
project.com/kfhjdsg/index.php/fkdhsg - Opens a 404 (but the CSS and other resources are not loaded too).
I'm sure both of these should open the 404 since there's no such routes in my project.
I also checked for the same behavior on the Laravel documentation website (I assume its built on Laravel).
http://laravel.com/docs/5.0 - Actual URL
http://laravel.com/aaa - A nice 404 page
http://laravel.com/aaa/index.php/docs/5.0 - Laravel documentation page again, same as the first one
What might be causing this? How can this be solved?
Why would Laravel even consider the 'index.php' in the middle of the URL?
Does this have anything to do with the .htaccess file? (I didn't edit it though)
The problem is inside the Symfony Request class and how it determines the base URL. Basically it assumes that if you have a request like aaa/index.php that your currently running script (named index.php) is inside the directory aaa takes aaa/index.php as base URL.
Later it will then be stripped from the actual request URI.
I fixed this unwanted behavior with a pull request that is currently under review. I will update this post as soon as it gets merged.
Same issue i was facing in laravel 3 when i was skipping public from url. then i have placed another htaccess file in public folder.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I'm developing a new website using codeigniter, this is my first codeigniter experience. I suspect that there is something not working with the 404 error, when I try to load a controller that does not exist, or a wrong function of an existing controller, I get back the standard webserver 404 error, and not the codeigniter one.
I did not touch the "404_override" option in the route config file.
Is it normal? I expect (but maybe I'm wrong) that in these cases the show_404() function is called.
Is your .htaccess file correctly set up?
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
You have to setup an .htaccess file in order to have custom error pages working. Checkout the official documentation.
Codeigniter should be showing it's 404 page, unless you did not remove the index.php from the URI. In that case you can try to open another file without touching CodeIgniter. Take a look here to see how to remove index.php using .htaccess.
Update:
There seems to be a solution for ISS: ISAPI_Rewrite Lite (free, lite version of a commercial product). I found it here