How to forward non-www URLs to www URLs - ruby-on-rails

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.

Related

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

IIS Site Bindings

I have a web website in IIS 6.1, with a Self-signed SSL. The website contains 3 web applications, all setup to use https as binding. Whenever I browse the application, the URL shows as
https://localhost/mysite1/default.aspx
I was under the impression that by adding a Site binding to use the computer name instead would change the URL to something like:
https://myservername/mysite1/default.aspx,
which means it will no longer complain about the SSL certificate being invalid when accessing the website, as the SSL is issued by "myservername"
I used the following command:
cscript.exe //nologo %systemdrive%\inetpub\adminscripts\adsutil.vbs set W3SVC/2/SecureBindings “:443:myservername”
My application identifier (2), which is shown under the "Sites" node.
After running the command, the URL is now directing to:
https://myservername.xn--9o0a/mysite1/default.aspx
That obviously doesn't work... it added .xn--9o0a to the URL??? What am I missing?
After doing some googling I managed to find this article that explains everything and how to fix the issue I was having.
http://gavinmckay.wordpress.com/2009/03/24/howto-fix-wcf-host-name-on-iis/

lvh.me:3000 no longer resolving to localhost:3000 for testing subdomains in development

I followed Railscast 121 to set up subdomains for my site, www.blog.com, and got everything working in development. I could use lvh.me:3000 to access my application at both the root url www.blog.com and at the specific subdomains I set up e.g. john-doe.blog.com
After pushing to Heroku, I can no longer connect to the root url at lvh.me:3000. What could be causing this?
Symptoms in development environment:
I can access www.blog.com through localhost:3000.
I cannot access www.blog.com at lvh.me:3000. but CAN still access john-doe.blog.com.
I opened a DIFFERENT application www.secondapp.com, and the root path for this also works at localhost:3000 but not at lvh.me:3000. I have not set up any subdomains for secondapp, but tried the url john-doe.secondapp.com just in case, and for some reason, this works. Very strange...
I must have inadvertently adjusted some files, but I don't know where/how. It's completely beyond me why a completely different app would work with a subdomain for an unrelated app. Any feedback would be much appreciated.
This is because of the current godaddy outage. Once their DNS is back up, it should resolve correctly.
In the meantime, you can try editing your hosts file.

MVC.NET 404 outside of Domain

I am trying to get a demo site for a client setup. This is the 1st application my company is doing in MVC.NET, so I get to experience all the new things to find out (and all the headaches it'll cause).
Anyway, the site works fine locally (localhost) and on the server inside our domain. External users not on the domain however, only get 404 errors. I've tried several different settings/ config options I've found on this site, but nothing is working. I don't know if it's a web.config issue or an IIS issue, or even simply a permissions issue (though it has all the same permissions as the other sites we run with Web Forms).
IIS: v7 in intergrated mode.
Windows Server Web
Well, because you received a 404, the server is being reached okay which is a good sign. (Dealing with firewall issues at a company is always a lot of fun.)
A common problem for something like this is the use of virtual directories to host the website. For example, if the address to your site is http://example.com/MySite/, in MVC that would translate to: /MySite/View/Index.aspx. HOWEVER...if you are using virtual folders, /MySite/ may instead point to another spot on the server (e.g. C:\WebSites\MySite). If you are indeed using virtual paths, make sure you have your files stored at the correct path.
There is a troubleshooting tutorial here: http://support.microsoft.com/kb/248033
thanks for the answers everyone. Turns out it was something with our DNS routing setup with the sub-domains. It was getting rerouted to a place that didn't exist. Our IT guy finally got around to fixing it (ugh!)

Hiding URL when redirecting

Is it possible that I can hide the URL where I redirect in CPANEL.
For example :
My Website : www.abc.com
My other website : www.xyz.com
When redirecting from abc.com to xyz.com I want that the adresse stay abc.com !
How can I make it in CPANEL. ??
The only thing you can do without using IFRAME is that, you will need to update your vhost config file for this for apache:
Following blog post should give you better idea about that:
http://blogs.digitss.com/apache/mod_proxy-mod_vhost_alias-to-host-multiple-domains-on-web-server-and-running-apache-iis-together/
Scroll down to title: How to host multiple domains/sub-domains on a web-server using Apache Virtual-Hosting (mod_vhost_alias)?
But I doubt how would you get to apache config if you are using shared hosting services?
Though I am not sure if you have your own server you can do it easily else talk to hosting support.

Resources