How to redirecting page to homepage use Kohana 3.2
I try use .htaccess file but failed:
RewriteBase /
ErrorDocument 404 http://www.domain.com/
ErrorDocument 400 http://www.domain.com/
ErrorDocument 401 http://www.domain.com/
ErrorDocument 500 http://www.domain.com/
ErrorDocument 403 http://www.domain.com/
Anyone help, please
This is the Apache "404" Page. Which would only come if there is no "index.php"-file, which should not happen at all in Kohana.
You can read about error handling in the guide http://kohanaframework.org/3.3/guide/kohana/errors .
Or for version 3.2 http://kohanaframework.org/3.2/guide/kohana/errors (which is down at the moment).
Following the 3.3 documentation this should work
class HTTP_Exception_404 extends Kohana_HTTP_Exception_404
{
public function get_response()
{
HTTP::redirect('/');
}
}
Related
I developed a system with REACT and Express.
It works well in local.
When I deployed to CPanel, I got 404 error for sub routers refreshing, so I added .htaccess like this.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
</IfModule>
After I added this, I got a CORS error when I call backend API with axios.
Please help me.
UPDATE
If I add .htaccess, I got this error.
Access to XMLHttpRequest at 'https://api.lightcoin.io/api/history?user=0x1C09d124d6c03EF63B1e0C3D1Af1b2eFE628ceE8' from origin 'https://lightcoin.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
If I remove .htaccess, it works well, but when the page of sub-router is refreshed, I got 404 error.
I have a react app hosted in S3. It is behind a Cloudfront CDN, which is reachable via a custom domain:
console.example.com -> CDN -> S3 hosted app
I also have a serverless application acting as my backend to handle API calls from the React app. This is also behind a Cloudfront CDN, which is reachable via a custom domain:
api.example.com -> CDN -> API Gateway
The front end is correctly configured to point to api.example.com. For the API Gateway, CORS is enabled.
When I navigate to the home page and attempt to login, console.example.com/login, I get the 405 Method Not Allowed error. Login, obviously using POST
I verified that the following curl is successful, when hitting the backend via API Gateway endpoint, Cloudfront Domain and the custom domain, effectively ruling out any API Gateway issue.
curl:
curl --header "Content-Type: application/json" \
--request POST \
--data '{"email":"name#test123.com","password":"xyz"}' \
https://api.example.com/login
In my research, I have found that S3 does not support POST. I have also found similar questions such as this and this, which were not helpful in my case unfortunately.
It is also worth noting that running my frontend and backend locally, works just fine, leaving me to think the S3 issue is my blocker here. But I'm not sure why. My POST endpoints are not trying to POST an object to the S3 bucket, they should be using the bundle.js file to hit the api endpoint.
So what am I missing? While I am not a frontend specialist, I assume others host react apps on S3 and can hit their api's just fine no?
I have intentionally not included the code as there would be a lot to digest there but am happy to include any that would be helpful, such as serverless.yml files or cloudformation templates etc. Any help would be awesome.
**** UPDATE - Added Cloudformation template for frontend Cloudfront CDN ****
Distribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
-
# Use the Website as the origin
DomainName: !GetAtt 'Website.DomainName'
Id: !Ref Website
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
Enabled: true
HttpVersion: http2
DefaultRootObject: index.html
CustomErrorResponses:
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /index.html
- ErrorCode: 403
ResponseCode: 200
ResponsePagePath: /index.html
DefaultCacheBehavior:
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
DefaultTTL: 60
ForwardedValues:
QueryString: true
Cookies:
Forward: none
# The origin id defined above
TargetOriginId: !Ref Website
ViewerProtocolPolicy: "redirect-to-https" # we want to force https
# The certificate to use when using https
Aliases:
- console.example.com
ViewerCertificate:
AcmCertificateArn: arn:aws:acm:us-east-1:11111111:certificate/11111111-fa9b-4705-b9d2-11111111
MinimumProtocolVersion: TLSv1
SslSupportMethod: sni-only
I updated CustomErrorResponses to include 405 and I no longer get "405 Method Not Allowed" error:
CustomErrorResponses:
- ErrorCode: 405
ResponseCode: 200
ResponsePagePath: /index.html
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /index.html
- ErrorCode: 403
ResponseCode: 200
ResponsePagePath: /index.html
I am working on a project that integrates WooCommerce with Ionic 3 and I am having problems with the signup and checkout functionality. I am able to read products and login from my WooCommerce site, but every time I do a post request, I am getting these errors:
{"errors":[{"code":"woocommerce_api_authentication_error","message":"Invalid signature - provided signature does not match."}]}
How can I fix it?
Make sure you have the following code in your .htaccess file on the top. You can find this file in the root of your WordPress.
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $l [R=200,L]
Also enable CORS on your browser.
I've installed a CakePHP application onto App Engine, and I'm redirecting URLs into it using a wildcard URL in my app.yaml:
url: /.*
script: app/webroot/index.php
The documentation states that /_ah/* URLs will be ignored (I don't know what these are for yet), but they are being caught by my CakePHP app and throwing errors into the error log. I also suspect this is the cause of 500 errors with an appengine error of 204 that keep happening randomly.
Does anyone have a solution for this? How do I ensure that the /_ah/ urls pass through to the app engine and not my specific application code?
Example error:
E 08:51:48.957 2015-03-17 404 841 B 304ms /_ah/start
0.1.0.3 - - [17/Mar/2015:01:51:48 -0700] "GET /_ah/start HTTP/1.1" 404 841 - - "****.appspot.com" ms=304 cpu_ms=416 cpm_usd=0.000094 loading_request=1 instance=0 app_engine_release=1.9.18
E 08:51:48.854 error: [MissingControllerException] Controller class AhController could not be found.
MissingControllerException is thrown by my app.
Request to /_ah/start is an initial request from Appengine itself, to initialize your app. I think you can ignore it, if you don't need to do anything special. Or return empty response.
See docs: https://cloud.google.com/appengine/docs/php/modules/#PHP_Instance_states
I have in my .htaccess file the following,
ErrorDocument 404 /404.php
RewriteEngine on
ErrorDocument 404 /404.php
# Redirect Writeback
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /user.php?u=$1 [L]
# Redirect Rule
RewriteCond %{THE_REQUEST} \?u=([^&\ ]+)($|\ )
RewriteRule ^ /%1? [L,R=301]
ErrorDocument 404 /404.php
As you can see I am trying to redirect if the page is not found, but mod_rewrite is preventing it from working, so I put it in multiple places to see if it made a difference, but it doesnt. how can I fix the 404 redirect and still have the other rewriteruile working as it should? To clearify, if you go to jnetscripts.com/multimedia it's actually pointing to file jnetscripts.com/user?u=multime.
UPDATE:
Ok I fixed this issue inside my user.php file using the following code, hope this helps anyone with same issue I had.
$numrows = mysqli_num_rows($user_query);
if ($numrows < 1) {
header("location: /notfound.php");
}
Because you are internally rewriting to a page user.php that actually exists, the ErrorDocument will not get triggered.
You can use the technique you are doing by testing if that thing exists in your database and redirect to the 404 page with:
header( "HTTP/1.1 302 Moved Temporary" );
header( "Location: /404.php" );
exit();
This will redirect to the 404 page, and /404.php will be displayed in the url bar.
An other way of handling is, by detecting if that thing exists in the database and include the 404 page. If you have a 404-header in your 404.php, then the header is not required. The client will see example.com/blah in the url bar, which will be internally rewritten to user.php?u=blah.
header( "HTTP/1.1 404 Not Found" );
require_once( "path/to/404.php" );
exit();