Made a little "url2hostname" extension to chrome that saves me the 1.42 seconds of url clicking and renaming every time i open a local html file in chrome. I'll write it down for consistency and repetition.
I have a virtual host set up for a dropbox directory. So in httpd-vhosts.conf:
<VirtualHost *>
DocumentRoot "C:\Users\hns\Dropbox\Webb"
ServerName localhost
<Directory "C:\Users\hns\Dropbox\Webb>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory> </VirtualHost>
So in "C:\Users\hns\Dropbox\Webb"
is where I keep lots of webpages that I just want to test locally (and they must be served by apache to work properly). When I open them in chrome the url gets messed up like "file:///C:/Users/hns/Dropbox/Webb/f/index.html"
for example. So in this case I have to select the "file:///C:/Users/hns/Dropbox/Webb"
-part of the url and rename that to the servername so it becomes: "http://locahost/f/index.html"
.
So when I've opened a local html file and click the chrome extension it just replaces the path and protocol in the url and goes to the resulting url (which is then loaded correctly):
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.query({'active': true, 'currentWindow': true}, function (tabs) {
var currentURL = tabs[0].url;
newURL = currentURL.replace("file:///C:/Users/hns/Dropbox/Webb", "http://localhost");
chrome.tabs.update(tabs[0].id, {url: newURL});
})
});
Hey, at least I learned something :)
EDIT:
The real problem was not Apache but Chrome and cross origin:
Due to the "same origin policy", sometimes sites content cannot be properly displayed locally. So in my case the problem could have been solved by just turning that policy off by starting chrome from a shortcut with flags like –allow-file-access-from-files
or
–disable-web-security
.