Get error 404 page not found - ruby-on-rails

My site running yesterday very well but suddenly today get "404 page not found" error. My site developed in Ruby-on-Rails and MySQL database.
Not Found
The requested URL / was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Why do I got this error? Its server issue or any code issue on server?

Can you access the /some_controller resource directly if you point your browser to it? The same holds true for your CSS files. Can you post a snippet of the HTML source that includes a the HREF's or the SRC's for your links/CSS?
Edit...
Now that I look at that rewrite rule, of course it doesn't work.
^/?$
That's only going to match a URL at /. Change it to:
RewriteRule ^(.*)$ http://127.0.0.1:12007/$1 [P,QSA,L]
And it should tick. Note that the above will proxy all requests to Rails. You should probably host your media outside of Rails' control, but that's an exercise for the reader.
Source: Ruby on Rails application only works if the address contains the port

Related

How to forward non-www URLs to www URLs

I've had an issue with Google Adsense not being able to access their config file (ads.txt) on my Rails site. I have put it in what I think is the correct folder (App -> Public).
In summary, this is the situation for which URLs work vs not:
[webURL].co.uk/ads.txt (works)
https://www.[webURL].co.uk/ads.txt (works)
http://www.[webURL].co.uk/ads.txt (works)
https://[webURL].co.uk/ads.txt (doesn't work - hangs)
http://[webURL].co.uk/ads.txt (doesn't work - error - HTTP Status: 404 (not found)
So my guess is that Google is trying to reach ads.txt via a URL without a www (the two bottom of the list above).
A couple of other points:
My Rails app is hosted on Heroku and I have a GoDaddy domain
On Godaddy, I have domain forwarding already setup, and so [mysite].com gets forwarded to www.[mysite].com.
So my question - how do I get URLs which don't have 'www' in them, to redirect to the equivalent URL with 'www'?
Any ideas?
Thanks in advance!
I resolved this by setting up Cloudflare and configuring some forwarding rules.

rack-rewrite - rails3.2 - heroku - redirect hardcoded image urls

My images were all held in the app itself and so were referenced with /images/12345.jpg which in some places has been hard coded into the content of the cms, with or without the full url.
The images have now been moved to s3 and so I want to add a redirect for urls that are of the following formats:
/images/12345.jpg|png|gif
or
http://www.example.com/images/12345.jpg|png|gif
(but only for only numeric filenames)
and point them to
http://my.images.images.s3.amazonaws.com/540x310/12345.jpg|png|gif
I currently have
use Rack::Rewrite do
rewrite %r{images\/(\d*.)(jpe?g|png|gif)$}, 'http://my.images.images.s3.amazonaws.com/540x310/$1$2'
end
But this doesn't seem quite right.
UPDATE------
of course the URL in the source doesn't change, I should have realised that. Clicking the link directly returns an error:
No route matches [GET] "/http://my.images.images.s3.amazonaws.com/540x310/13135.jpeg"
(note the leading slash)
So the rewrite is working but it thinks it should be routing to an internal link not an external URL.
UPDATE2------
Changing to
r302 %r{(?:images\/)(\d*.jpe?g|png|gif)$}, "http://my.images.images.s3.amazonaws.com/540x310/$1"
will now redirect if I go to
http://www.example.com/images/13135.jpeg
but is not rendering the images in the site itself.
this was caused by the url on the localhost still pointing to the live url and therefore the 301 rewrite never being called.
So the local deployment had the live URL hardcoded into the page, i was then changing this and pointing my browser at localhost.
In the page though the old URL remained which meant the page was looking to the live server for a possible redirect which had never been dpeloyed

JRuby/tomcat 404 errors in rseponse to ajax GET

This problem appears specific to routing for JRuby ajax requests. My page sends an ajax GET which works fine in rails development mode. When moved to tomcat via warbler, the request is generated correctly, but tomcat responds with a 404 error.
In other words, the line in routes.rb get '/sector/method' is sufficient that http://localhost:3000/sector/method is processed by Webrick, but if I change the port to 8080 (tomcat) I get a HTTP status 404 The requested resource (/sector/method) is not available.
Apparently tomcat needs to be told it is OK to process the GET even though there is no corresponding file to be found. Right? Fixes?
Thanks.
Are you sure your request point to correct address? if application works, there is no way that GETs does not. Please try to put the request directly into your browser and check...

symfony - 500 error page customisation problem

I am ready to push a site to production (currently on staging), but I'm having a slight problem with the internal server error 500 page.
I have created a file in web/errors/error500.php and I've also got: ErrorDocument 500 errors/error500.php in my .htaccess file
The problem is, if there is a 500 error in the admin, it displays the symfony default 500 page instead of mine in the errors folder.
Does anyone have a rough idea why this is?
I've cleared symfony cache, cleared browser cache and used several browsers.
Thanks
The standard Symfony way of doing this isn't with an Apache ErrorDocument directive, but simply by putting your error page in either <project>/apps/<appname>/config/error/error.html.php or <project>/config/error/error.html.php, for per-app or general error pages respectively. See this checklist item on the very handy Symfony Deployment Cheat Sheet.
Also make sure you are not in debug mode when you test this otherwise it will still show full stack trace.

how to handle errors like 404 / 500 in rails3

Hey, I hope you can help me.
I am trying to find a way to direct the user to the default error pages 404.html and 500.html in my public folder.
So when there is a routing or nomethod error it should be directed there to.
I already tried some stuff in my application controller but it didnt work.
Many thanks!!
Rails does this for you automatically when running in production mode. When you upload your application to a live server, Rails takes care of handling those exceptions and rendering the correct error pages with the correct header status. If you're trying to see what those pages look like (for testing or something), just access them directly via http://localhost:3000/404.html
Whenever you set up your Rails application on a live server (let's use Apache as an example), you give the site root as the /public folder in your application. Then, whenever a request is made to that server address, Apache first looks in that public folder and tries to serve a static asset (this is a configurable option in [environment].rb). If it can't find the requested page, then the request is forwarded through the Ruby stack.
When in production mode, if Rails encounters an error that isn't handled (i.e begin, rescue), it throws the error the whole way up to the stack, which then tells Apache (again, in my example) to render an appropriate error.
Here are some common errors that you'll see in development mode and what they render in production mode:
ActiveRecord::RecordNotFound => 404 (page not found)
nil.method => 500 (server error) unless you turn off whiny nils
ActionController::RoutingError => 404 (page not found)
Happens automatically if run in production mode - no need that you do that manually.
Have a look at this post to redirect all requests causing a Routing Error.

Resources