rails application redirecting without the prefix - url

I have a problem with my web app..the urls all work fine with the exception of the following case.
When I try to access my app without the www prefix
http://myapp.com/mypath
the url changes to www.myapp.commypath - no slash between domain name and the path
every other combination of the url works just fine, but this one, any ideas?

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.

HttpModule URL Rewriting - 404 error in IIS

I have created a very simple HttpModule that rewrites the incoming path to one that matches a route in MVC. ex.:
http://www.example.com/cars.html -> http://www.example.com/Home/Vehicles/3
To rewrite the path I simply use RewritePath on HttpContext.
The problem is that while it works in IIS Express, this doesn't seem to work in IIS. I can see that the URL is rewritten, but I get a 404. It seems to happen beacause instead of matching this rewritten route against the registered routes, the StaticFileHandler tries to handle the request.
So when http://www.example.com/cars.html is entered into the browser, on the IIS error page, I see the Requested URL:
http://www.example.com/Home/Vehicles/3
which is correct, but I will also see that it tries to load a physical path: X:\Project\Site\Home\Vehicles\3.
If I enter the rewritten path into the browser, the page is loaded and works as expected, so the routes are ok.
Any ideas how could I rewrite the path from my HttpModule so that the rewritten path is than matched against the registered routes in MVC? Or any ideas what could be missing? :)
Cheers
Adam

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

ASP.NET MVC server path is different from application path

I have an unusual circumstance where our web server inserts a folder into the url path before loading the page. Let me give you an example:
The app is called equipment and if I were to run it on a normal server setup, it would look like:
www.site.com\equipment\home\index
BUT when I run it on our server, it inserts "idn" in the url:
www.site.com\idn\equipment\home\index
The messes up my relative references. The MVC functions want to redirect to use "\equipment\" instead of "\idn\equipment\". This happens with Scripts.Render(), Return View(), etc.
Also, I can't hardcode the "idn" into my urls b/c then it is no longer relative and it won't work on my dev box or test servers b/c they don't have a "idn" subfolder in localhost.
I also tried functions such as Request.ApplicationPath and what not but none of them return the "idn" in the result.
Is there way to MVC to know that this "idn" was inserted into the url and account for it?
Thanks!
Create your application on the test/production server in the idn folder, then it all works.

Grails: subfolder is ignored

I have a grails app running on a URL something like -
http://{ip address}/appName
Now I am trying to have a sub-folder of my domain pointing to that app server.
Something like -
http://www.example.com/subfolder/appName => http://{ip address}/appName
When I load the url with subfolder the grails app responds properly and redirects to the first page of the app (as expected). But the problem is - all other URL's in the page (controllers, css, image files, etc.) ignores the "subfolder" at the end of the URL.
Like, instead of trying to point to
http://www.example.com/social/appName/{controllerName}
http://www.example.com/social/appName/{cssFileName}
etc
Everything points to
http://www.example.com/appName/{controllerName}
http://www.example.com/appName/{cssFileName}
etc
I have tried modifying grails.serverURL and grails.app.context. But still the same problem.
You could try:
grails.app.context="/social"
See also: grails 2.0 - correct use of serverURL for production?

Resources