History.js - subdirectory urls with # not #./ - single-page-application

I'm building a single page application in a subdirectory of my site and have started using history.js for updating the url.
The HTML4 fallback with hashes by default includes the whole path after the hash - including the subdirectory. If I make these relative paths then it includes an ugly "/#./".
I'd like to know how I could achieve the following.
HTML5 url
mydomain/mysubdirectory/myhistoryjspath
HTML4 url
mydomain/mysubdirectory/#/myhistoryjspath
Any ideas?
Thanks

Related

Play framework routes: How to redirect from another location

Hello I am a newby when it comes to the play framework (routes), so bear with me please.
I have a two website on a server that use a same css file.
However, the challenge is that the website have a different home '/'.
I don't know how to use routes assets to redirect properly to the right css file location.
For example, in the case of website.com and another-website.com I tried adding the following.
### NoDocs ###
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
The problem is that website.com accesses the css file correctly, but another-website.com can not access the file.
At this point assets/styles/somecss.css is added to locationofpublic/assets/styles/somecss.css for website.com, but to another-website.com/assets/styles/somecss.css for another-website.com
It gives this error:
Refused to apply style from 'another-website.com/assets/styles/somecss.css'
because its MIME type ('text/html') is not a supported stylesheet MIME type,
and strict MIME checking is enabled.
Question:
How can I make another-website.com use locationofpublic/assets/styles/somecss.css as well, what do I add to the routes file?

DRUPAL 7 - Clean URL and relative path : it's doesn't work

I start with Drupal and I have read some of topics about my problem but I didn't found the solution.
My problem is the following :
On my website (for the moment in localhost) I use Clean URLS module. The problem is when I enable this module and when I use the relative path of my files, my pictures or links don't work.
For example : src="./sites/default/files/styles/large/public/add_tool_version.png".My pictures are not visibles.. I don't know why this module doesn't work with the relative path.
But when I disable the module, the link is works fine.
Please, can an you help me ? Do you have any solution to fix it ?
Thanks in advance for your answers
Try using absolute paths. In you case with image it would be like:
src="/sites/default/files/styles/large/public/add_tool_version.png", without dot.
This absolute path will always refers to that image instead of relative path - it depends on you current directory or page.
The problem with clean urls is the way browsers read urls and interpret them as directions in a file directory. Lets say you are at http://www.example.com/?q=node/11, or, with clean urls enabled, at http://www.example.com/node/11.
When enabeling clean urls, and putting a link with a source into some node, your browser will search for your files in the folder that is specified in your url. Thus, when you declare the source to be sites/default/files/styles/large/public/add_tool_version.png and are on the url http://www.example.com/node/11, then the browser will look for the file in the directory node/11/sites/default/files/styles/large/public/. Usually this would work, but in drupal, there actually is no such folder. All drupal pages are just versions of the index.php in your base-directory. In drupal, the url doesn't have anything to do with file structure - unfortunately, the average browser doesn't know that.
Without clean urls, however, your browser will recognize the url as a combination of a base path (www.example.com) and a query (?q=node/11). It will therefore look for your file starting from the directory specified in your base path.
If you still want to have your relative paths working with clean urls enabled, you can use the function base_path() in front of your actual source.

How to handle stylesheet links when local and server directory structures don't match

The document root of my website is directly the server webroot (public_html), and not in a separate subdirectory. This creates a problem for me, because my local website is in a project folder (which is required by my editor, NetBeans), which means that href links to stylesheets need to be of the form:
/projectfolder/stylesheets/stylesheet.css
But on the server, since the website is directly in the webroot, the href url would have to be:
/stylesheets/stylesheet.css
When I asked my host about this, they said I would have to refactor my project to change all the stylesheet links. But I don't know; it seems kind of funny to have to refactor (then "unrefactor") the local website every time I want to upload it to the server. Any other solutions out there?
You don't have to use absolute paths to your stylesheets. Use relative paths instead. Then it won't matter where your files are hosted, so long as they stay in the same positions relative to each other.

IIS CustErr CSS Question

I'm trying to style the custom error pages in IIS7 with a linked CSS style sheet.
This works.
<html><head><title>404 - File or directory not found.</title>
<LINK href="http://stage.mysite.com/custErr/css/style.css" rel="stylesheet" type="text/css">
</head><body>Page Not Found</body></html>
I've created a virtual directory in mysite called custErr that contains the css and images needed.
But to make it easier to deploy I'd like to have it relative like this...
<html><head><title>404 - File or directory not found.</title>
<LINK href="../css/style.css" rel="stylesheet" type="text/css">
</head><body>Page Not Found</body></html>
After trying this I find that relative paths don't seem to work. In fact a style sheet in the c:\inetpub\custerr\en-US folder doesn't work either.
Where are these pages being served from?
Is there an easier way of doing this?
So I don't have to modify each and every absolute path for each environment?
I know this is a late reply but the reason why the relative paths don't work (I think) is because if you hosted a site such as www.myfavouritephotos.com and on visiting a directory on that site such as www.myfavouritephotos.com/images/ which is a directory in your website that doesn't have a default document like Default.aspx or whatever your site is set up as serving as a default page, IIS would return a HTTP Response of 404 for not finding a page to serve up or a 403 response because the user may not have the necessary rights to view the content of the directory under that url.
IIS by default would serve either the 404.htm or 403.htm file from within the c:\inetpub\custerr\en-US directory by default but when you replaced it with a custom htm file that replaces 404.htm, the relative path to the stylesheet you reference from that htm file would make a request at what the original url made to the server was so www.myfavouritephotos.com/images/(../css/style.css) which would result in an incorrect relative path so it may be able to be avoided by using a reference to a stylesheet with www.myfavouritephotos.com/css/style.css

Django not displaying image in css

I have a django application.I have added image (url) in css,it isn't displaying the image.
But when I used it as a html file,it is displaying the image.Should I set any url in settings.py for this? Source [shown here][1]. [1]: http://dpaste.com/164620/
That is definitely a local path. You need either a path relative to the doc root (by default, Django doesn't serve media files, it's discouraged to let it do that outside testing environments) or an absolute URL if the file is on a different (sub-)domain (e.g. a local Apache vhost that serves the media files).
If you're using relative paths, beware that the path will be relative to the page the path is mentioned on (i.e. if you put it in a CSS file, it will be relative to the CSS file; if you put it in a template, it will be relative to whatever page is shown with that template).
If you're using absolute paths, beware that the path will be relative to the doc root of that (sub-)domain.
EDIT: NO, really. It's the path. A path in CSS or HTML will be parsed by your browser. So even if you run the thing on localhost, an absolute path (starting with /) will be parsed as relative to the document root (i.e. handed over to Django's URL resolution).
If you have the site running on http://localhost:8000, /home/logic/quote/template/hummingbirds.gif will be treated as http://localhost:8000/home/logic/quote/template/hummingbirds.gif, i.e. your browser will make a HTTP GET request to the server running at localhost:8000 for the path /home/logic/quote/template/hummingbirds.gif. If the server is Django, it will try to find a rule matching /home/logic/quote/template/hummingbirds.gif in your urls.py. You can't refer to a file in your filesystem by just passing the local path.
If you want to serve static files (e.g. images) with Django (i.e. on the same domain and port Django runs on), you need to configure it to serve these files first like so: http://docs.djangoproject.com/en/dev/howto/static-files/
If you want to refer to a file on your filesystem (BAD practice and needs to be replaced if the thing EVER goes online), you need to use the file:// protocol explicitly. Absolute URLs (i.e. without protocol prefix and domain name) will always be treated as relative to the current protocol and domain.
is /home/logic/quote/template/hummingbirds.gif your image web path? it look like a local path.
does it show when you type http://your.host/home/logic/quote/template/hummingbirds.gif
if you set a background-color, does the color appear?
suggestion:
on firefox with firebug:
enable css warning
lokks at the parsed css file (css tab) to see if your rule is well writen
inspect the element your background should be on and verify it has the css rule applied and not overwriten

Resources