Is there a way to redirect traffic from file extension - html

I currently have the piece of code that allows you to go to one of the pages on my site without having to type in the file extension in the url. I am wondering if there is a way to redirect all traffic from users using the file extension in the link, to the link without a file extension. For example, if a user types example.com/about.html I want it to redirect it to example.com/about.

Related

Serving local file:/// links and AppCache

I'm making a webapp for members of my caving club to search through and view cave survey note PDFs. It works fine, and I got the AppCache working for the web version of it.
However, since the PDFs are quite large and slow to download, and many members have the PDFs on their local machines from the same SVN the website gets them from, it would be ideal for them to be able to use a page with links to a local SVN folder of their choosing.
The design goals:
The site displays links to PDF files on the local filesystem
Whenever I add features to the site, users get them automatically the next time they open the page and they're connected to the internet
But after the first time they open the page, the site works offline.
Sadly web browsers don't appear to support this useful combination of design goals at once.
I can satisfy #1 by having users download a copy of the site, add their local SVN path in a JS, and open their local copy in the browser, so that file:/// links work.
I can satisfy #2 by having absolute links to JS bundles on the server.
I can satisfy #3 by using the AppCache.
I thought I could get clever by having the copy of the page on the local file system have <html manifest="https://myserver.com/myapp.appcache">, but unfortunately Chrome doesn't seem to allow a local file to use an app cache manifest hosted on a server, for seemingly no good reason to me.
Does anyone know of another way I could satisfy all 3 goals?
Perhaps there's some simple program/config I could give my friends that would intercept web requests to https://myserver.com/some/folder and instead serve them out of a folder on their local file system?
Andy,
I know this post is a bit old but came across it looking for something else related to AppCache. My understanding it that the html page and the manifest must reside in the same domain for it to work. So I think you need to modify your design:
Create a JavaScript function that acts as a setting for the user to enter the path to their local copy of the PDF's. Store this information in localstorage.
Create a html template page for the document links.
Create a JavaScript function that populates the html template page with any documents and links the user enters.
This way, the users visit your application online and it uses appcache to store itself and the JS files for offline use. To access the PDF's, the user clicks a settings button that launches a page to collect path information and saves the information in localstorage. The users can then access the template page which will populate with the documents they entered.
Here is a good intro to localstorage: [http://www.smashingmagazine.com/2010/10/local-storage-and-how-to-use-it/]

Redirecting domain name to open an HTML page

I have a script that is being hosted on my Raspberry Pi over my local network.
I'm curious how I would go about being able to type in inventory in my web browser on my PC to be able to open up the HTML page that is generated by the script on my Raspberry Pi?
To elaborate, how would I have my browser to know at //pi/users/home/script/some.html when I type in inventory in the address bar? (Do I set this in my router or in a config file on my PC)
I think what you are looking for is the 'keyword' entry in a bookmark's properties.
You first create a bookmark of the webpage you want to link to. Then open the properties for that specific bookmark and enter the keyword of 'inventory'.
This way, every time you type in 'inventory' in your browser address bar, you will go to that page.

Choosing a File Path as Part of a HTML form

I'm developing an intranet site for my company, and part of the task it has to perform is to hold a database of files and their locations as submitted by users (the files are on a network drive and people viewing the database can click links to the files to access them). I have it working now using a standard text input field where the user enters the path to the file, but is there a way of giving the user a Browse... button to choose the path instead?
Using the type="file" option isn't suitable as I don't want the actual file submitted, and it only gives the filename, not the path for security reasons. But that's the sort of thing I'd like.
Thanks!
No.
Browsers aren't designed to expose details of the client file system to the server.
Build your file browser server side instead. The server should be able to access the same network drive.

Default folder and filename for html file upload

I'm using a jQuery Ajax plugin to upload image files from a local machine to a webserver. The webpage presents a button marked Upload Image File, the user presses the button and selects the file to upload from a popup directory listing presented by the browser, PHP at the server stores the image file away, and all that works fine.
When the user views the webpage to upload the image, the file path of the image on the local computer is completely predictable. This is part of a workflow where the file names and folders are well-defined.
I understand that the file upload mechanism in the browser is deliberately not changeable, because that would be a security worry. But, is it possible to give it a hint, so it presents the popup directory listing with the correct file in the correct folder already selected, so the user just has to hit return to confirm the upload?
I looked at Set a default file name/directory for upload on web form by modifying the html but found nothing I could use. Is this hinting impossible?

Auth redirect - opening a local HTML document in a new tab in a Firefox extension

I am currently trying to port a Chrome extension to Firefox.
The Chrome extension has a "Login" page, which is opened in a new tab as an HTML document. The HTML document is stored in the local directory with other extension files. The user inputs a URL which should represent a server running our application, where the user will be asked to login. After a successful login, the user is redirected back to the options.html page, which is updated to show the user's preferences.
I would like to duplicate this in the Firefox extension, i.e. I would love to avoid writing anything in XUL to build an options page.
I tried opening a new tab with my HTML page like this:
var url = "chrome://myextension/content/options.html";
var win = Components.classes['#mozilla.org/appshell/window-mediator;1']
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow('navigator:browser');
win.gBrowser.selectedTab = win.gBrowser.addTab(url);
But I don't like this for a few reasons: 1) The navbar in the new tab displays the "chrome:// ..." URL, and 2) it breaks the authentication process. The authentication is done using an OAuth type system, and the current URL is passed into the API so that the user can be redirected back upon successful authentication. The authentication fails with "chrome://" as part of the URL.
Just out of curiosity, I tried hardcoding the URL like this:
http://myextension/content/options.html
And the user is actually successfully authenticated, but then the redirect obviously fails afterward.
The Chrome extension seems to work with no problems or weird hacks. From what I can tell, opening it works like this:
chrome.tabs.create({"url":chrome.extension.getURL("options.html"), "selected":true});
And referencing the URL of the tab later so we can be redirected back to it just works like this:
var options_url = chrome.extension.getURL('options.html');
So, I'm wondering: what is the best way to open a local HTML document in a new tab with a Firefox extension, without using the "chrome://" "protocol"? Is there a similar way to how it can be done with Google Chrome extensions?
UPDATE 23/5/12
So this article says that chrome:// URLs are not accessible from the web, only locally.
http://adblockplus.org/blog/web-pages-accessing-chrome-is-forbidden
I think this could be the reason why my authentication was failing. I'm definitely looking for a way for my extension to display a local HTML file in a window or tab without using chrome://.
UPDATE 07/6/12
Here is my (hopefully temporary) solution:
The user enters the URL of the server running our application. He/she is redirected to the application login page, but instead of passing "chrome://myextension/content/options.html" as the URL to be redirected back to after authentication, I pass a phony URL, i.e. "http://myextension/thisis/madeup.html".
In my extension's overlay.js, I set up an HTTP request listener which listens for the phony URL being requested. When a GET happens for the phony URL, I cancel the request, and open the real, locally stored page at "chrome://myextension/content/options.html".
See the following references:
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIObserver
https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads#HTTP_Observers
If you're trying to do this redirect for an OAuth call you should try using OAuthorizer from Mozilla instead of doing the redirect work yourself. Hope that helps!