I've noticed many sites use some strategy to host their two sites for pc and mobile users on only one url. For example, https://read.douban.com , its pc site and mobile site uses one url, how does this happen? Note I'm not asking the responsive design because its mobile site does use responsive design itself. And I don't think it is a nginx redirect because the urls are the same. There is one link on the mobile site to switch between the two sites.
How does they make a single url host multiple websites? And how to switch between them?
Thanks.
I guess there are many ways. One way I know, is with Struts: Each request is going through Java logic and then an JSP page is sent to the user {This is a very simplified way to look at Struts}.
So, in this case a request comes from a mobile browser - will get a JSP made for mobile. A request from a PC will get a JSP for PC. The URL can stay the same.
If you separate the user request then you can hosting a single url to multiple websites?
So First detect the user request.
NB: I only consider the incoming user request is from PC or other devices(Phone, Tab, etc..)
STEP 01: request is from PC
// return negative value if the request is from PC
var myNavigator = navigator.appVersion.indexOf("Mobile");
So, based on myNavigator value, we make separate sites.
Tnx, Happy coding!
Related
I've got a requirement to detect if a webpage is being served on the internet or intranet, i.e. assuming a url of https://accessibleanyway.com, is the phone connected to the work wifi or to something else like their home wifi or the phone network?
What different ways are there to do this?
(1) Use WebRTC to get the local ip address. Not widely supported
(2) Try to access a local web page using jsonp/cors/iframe
The problem with 2 is that the webpage is https and the local resource is likely to be http which you can't do in IE afaik. If I make the local resource https then it's via a self cert which means installing CAs on the phones (can you buy certificates for the intranet anymore?)
Any suggestions?
The problem with (2) was that the same page was trying to use http and https, and even with an iframe you get issues.
What you could do instead is start on a http loading page, use an iframe to access a local resource which you can only access if you are on the intranet, jsonp will work fine for this. Once that's worked or failed, redirect to your start page with some token in the querystring to indicate that you are on the intranet or not
NB jumping from http to https would probably have some security issues if you are on the same website (authentication cookies being initially visible), but I would have thought it would be fine if you are going to a different one
Obviously there'll be some security needed around the token as otherwise the user could just generate their own but that's a different matter which depends on individual setups. It would obviously have to be generated by a server call, otherwise someone could just read the client code.
NB I think the IP address approach is never going to work as you have no way of knowing what a companies intranet setup looks like until you go there, so it's not a generic answer
I have researched the Internet to solve the following cross-domain web-client situation without luck:
A client browser with website A loaded wants to download a webpage-stream directly from website B and incorporated the steam into its DOM.
The boundary conditions are:
webserver of website B has no special policies for:
-cross-domain accesses,
-and/or special jsonp services.
I don't wat to use either:
-a proxy-service on my webserver, or
-using a third server such as http://anyorigin.com/, or
-depend on a particular extensions for the browser.
I understood that actual browsers don't handle 'X-Frame-Options' different that 'SAMEORIGN'
Do you guys have any feasible solution?
Is there a reason you don't iframe in the results of website b? That'd be the first thing I tried...
I'm afraid you'll have to patch the feed in at the server level. But at least, you can add a cache so it doesn't pull the feed in every request.
Edit: I'm assuming you don't want iframes
Im configuring a desktop and mobile version of my site and was looking to use js to test for browser dimensions and then load the relevant version, however the problem is if someone shares a link from the mobile version and sends it to a desktop user then they circumvented the check. Is there a way to configure .htaccess (or some other method) to have the address bar show 'mysite.com' even though i would be loading 'mysite.com/mobile.htm'? I know i can always use media queries but that has the downfall of loading unused assets, so this method would be alot better.
Use a rewrite instead of a redirect. With a redirect, the browser is instructed to go to another address. With a URL rewrite, the server just responds with the contents of a different URL.
For just this page it will be simple, but it could be complicated, based on your site.
Another way is to include a little JS in every page to make sure you are on the right one for the device and redirect to the other if not. It would help if there was some pattern to easily determine the corresponding page.
I am using Asp.net MVC3 and C# and IIS 7.5. I want that once user is registered he can browse my site using username.host.com and this username should be available to me in my URL so I can show the data related to that particular username only. All the logic is the same for all users. I don't want to do any fancy thing like if user1.host.com is entered then I want to redirect to a separate controller and action etc. All the application logic is the same for all users. I just want to change the way the url is shown in the browser.
Also, if possible I want this to work on localhost also in IIS/Cassini.
Eg: If I browse to jaggu.localhost:19883. It should send me to localhost:19883/Home/index/Jaggu (because by default Home is the controller and index is the method)
I am completely clueless on how to achieve this. Any help would be appreciated.
You may need a star A record, like *.host.com that points to your host.com site.
On your default page (or elsewhere via something like an IHttpModule) reroute the request to where you want the registered user to land.
Google: URL Rewriting for more information.
I want to implement https on only a selection of my web-pages. I have purchased my SSL certificates etc and got them working. Despite this, due to speed demands i cannot afford to place them on every single page.
Instead i want my server to serve up http or https depending on the page being viewed. An example where this has been done is ‘99designs’
The problem in slightly more detail:
When my visitors first visit my site they only have access to non-sensitive information and therefore i want them to be presented with simple http.
Then once they login they are granted access to more sensitive information, e.g. profile information for which HTTPS is used to deliver.
Despite being logged in, if the user goes back to a non-sensitive page such as the homepage then i want it delivered using HTTP.
One common solution seems to be using the .htaccess file. The problem is that my site is relatively large meaning that to use this would require me to write a rule for every page (several hundred) to determine whether it should be server up using http or https.
And then there is the problem of defining user generated content pages.
Please help,
Many thanks,
David
You've not mentioned anything about the architecture you are using. Assuming that the SSL termination is on the webserver, then you should set up separate virtual hosts with completely seperate and non-overlapping document trees, and for preference, use a path schema which does not overlap (to avoid little accidents).