Solve redundant hostnames in Play Framework - .htaccess

In my Play 2.4.x Web Application I am getting told by Google Analytics that I have two redundant hostnames namely
domain.net
www.domain.net
From an SEO standpoint it's important for me to fix this isse.
Normally this could be fixed with a .htaccess file doing a redirect from one of those two to the other one.
I want to know how I can achive the same solution using Play's application.conf file.
Reading the documentation I figured something like this could solve the issue:
%production%.application.baseUrl="http://domain.net/"
I am not sure though if this is enough.

What you want to do is create a filter that checks the incoming hostname, and if it's www.domain.net, redirect to domain.net. This would be equivalent to the Apache .htaccess. Of course, if you have a reverse proxy in front of Play (which you probably should, this is considered good practice) eg nginx or haproxy, then you can implement the redirect in there.

Related

Ignore last part of URL with .htaccess

We have a FAQ page /faq (tab style) where every question should have its own 'ghost' url/page. So users could visit eg.
/faq/question-1
/faq/question-2
/faq/question-3
The problem is question-1, question-2, question-3 are not actual pages but just sections on /faq. For SEO, aesthetics and usability reasons we do not want to work with ?q= or #
I've searched and tried every .htaccess thread I came across but without result.
Is there a way we can show the page/faq when visiting /faq/question-1 and keep the url /faq/question-1 with mod_rewrite? (we cannot hardcode it because we do not know all future question slugs) So basically something that tells the browser: if the first url part is /faq/, just ignore everything that comes behind but keep the url.
Thanks
This is a trivial rewriting task and it is unclear why this should not work for you:
RewriteEngine on
RewriteRule ^/?faq/.+ /faq [END]
Since you claim that you "tried every .htaccess thread you came across" and this clearly works the question is: why not in your setup? But since you did not tell us anything about your setup we cannot really offer more help...
These are some general hints though which you should go through:
Where did you implement the rules you tried? In the http server's host configuration or in a distributed configuration file?
If you are using a distributed configuration file (".htaccess") then how did you make sure such files are interpreted by your http server and how did you test that?
Did you check your http server's error log file for hints?
Did you make sure that you are not actually looking at cached responses? So did you really test with a fresh anonymous browser window using a "deep reload"?
Since the CMS you are using requires own rewriting rules, where did you add those rules you tried? Remember: the order is important!

Is there a way to use Node.js in conjunction with Apache the way PERL or PHP work?

Currently using Node.js to handle all our AJAX calls, which works brilliantly but (unfortunately) still leveraging PERL to draw in-line page content, when absolutely necessary - (for instance when Facebook or some other third party site needs to call our site and read specific Meta tags that are generated by the DB) - as well as handle file uploads and stuff of that nature.
I am trying to figure out what I'd need to do to have my web server (Apache) reach out to Node.js directly, so as to replace PERL in our mix.
Would really appreciate a pointer at some documentation that explains how to set this up or (less preferably) a response saying that at present such a configuration is not possible.
I'm rather confused by most of your question - my interpretation is that you have some URLs which you want to handle with node.js and some that you want to handle with Apache+Perl
The simplest solution is to make the 2 servers available at different URLs, e.g.
http://www.example.com:80 for the node.js
and
http://www.example.com:81 for the apache + perl
Alternatively you could use one of the servers as a proxy for the other, given a particular prefix in the path. Which way around you put the servers has a lot of implications for the performance profile of the system - but the safest solution is to use node.js at the frontend. It should be straightforward to implement this (although I'm not an expert on node.js). It's also quite possible to this the other way around - with Apache at the front using mod_rewrite (and optionally mod_proxy if you want caching):
RewriteEngine on
RewriteRule ^ajax/(.*)$ http://127.0.0.1:82/$1 [P]
(you'll need mod_proxy and a proxyPassReverse rule to clean up any redirects returned by the node.js server)
Another approach would be to run a content director in front of both the servers - although this adds additional overheads. For example using nginx:
location /perl/ {
proxy_pass http://127.0.0.1:81;
}
location /ajax/ {
proxy_pass http://127.0.0.1:82;
}
If you mean that you want all requests to be handled by node.js and some of the responses are partially made up from data accessible via Apache+perl then that's a lot more complex.
If you really love Perl like me, you may feel like this module:
npm install exec_perl
see: https://github.com/tlqtangok/exec_perl

Config mod_pagespeed for multiple domains

Is there a way to set multiple domains VirtualHosts with Google Pagespeed module?
I've tried this with ModPagespeedDomain with one domain of mine but not sure how to go about multiple ones I have about 14 on one server
I've also tried ModPagespeedMapOriginDomain but this doesn't seem to help either. I basically want combine_javascript and combine_css to work with all sites. I already have filters set up in the config file
ModPagespeed docs have a few examples for how to configure both server-wide and per VHost rewriters: https://developers.google.com/speed/pagespeed/module/configuration#virtual-hosts
You should be able to use ModPagespeedDomain to tell mod_pagespeed which domains to rewrite. Are basic rewrites like CSS minification and image re-compression working for you?
In order to get combine_* to work across multiple domains, you'll probably have to use ModPagespeedMapRewriteDomain to move them into one domain. Something like:
ModPagespeedMapRewriteDomain one.domain.com/shard1/ shard1.domain.com
ModPagespeedMapRewriteDomain one.domain.com/shard2/ shard2.domain.com
ModPagespeedMapRewriteDomain one.domain.com/shard3/ shard3.domain.com
ModPagespeedMapRewriteDomain one.domain.com/shard4/ shard4.domain.com
...
Then all rewritten resources from shard*.domain.com will be rewritten into one.domain.com.
Please read the documentation carefully, there are some assumptions that need to be satisfied for this directive.

IIS, Redirecting and HTTPS

I have an interesting issue with HTTPS ports not being handled properly. It is a relatively small issue and I bet it is pretty simple to solve, I am just not thinking of it.
We have a website served with IIS 6, www.mylongdomainname.com. We have a secure portal which is handled via https://www.mylongdomainname.com. Now we have several vanity and marketing URLs that we use over the phone like www.shortname.com, etc. I have two websites setup, one that handles all request with the header www.mylongdomain.com which actually serves the website. The other accepts any traffic and permanently redirects to www.mylongdomain.com. This way if we ever add any more domains, they will all end up at the one, also it redirect mylongdomain.com to www.mylongdomain.com.
Everything here works fine. The issue now is when I google "shortname.com," the first result returned is the same as if I were googling "mylongdomain" however, google has been able to crawl the other pages via https://shortname.com and index them that way. We dont have SSL certificates for these other domains, so when you click through, you get a nasty un-trusted error.
This really wouldn't be an issue if we didn't use these URLs over the phone, and you all know how many people don't know the difference between the URL bar and a search box.
any suggestions or tips?
I'd set up a redirect so that https://shortname.com is sent to http://shortname.com with a 301 (permanent) redirect. This will put an end to the nasty untrusted error immediately. Furthermore, this will also cause Google to slowly but surely update their index.
There are multiple ways to do this. If you're using IIS7 you can use the URL Rewrite Module and write a redirect rule to take care of it.
Or if you're not on IIS7 it may be perfectly acceptable to write some code to accomplish this. I wrote some ASP.NET I've used plenty of times to take care of this HTTP/HTTPS redirection. In your particular case you could simply take my code and call SetSSL(False) in the Application_BeginRequest function of your global.asax.

Delivering a file over ssl and non ssl (http and https) in IIS

To avoid mixed content warnings I would like to have a file that can be delivered under both protocols (http/https). Ie.
http://www.site.com/file.js
and
https://www.site.com/file.js
I've had a look at google analytics injection code and they use a diferent domain, i.e:
http://www.google.com and https://ssl.google.com.
Now I would like something a little 'cleaner'? I really don't want to have 2 websites to mantain. Does anyone know if this is possible in IIS?
Thanks
Guido
This doesn't have to be a different domain, it will typically use the domain just a different port. See "How to Setup an HTTPS Service in IIS."
EDIT
I see you you are talking about mixing SSL and non SSL, so if my answer above doesn't help. It seems that using relative URLs are the answer. Take a look at Http-https transitions and relative URLs.

Resources