Why do relative paths not work in CMS? - path

Why do relative paths not work in popular basic Content Management Systems which use "editable" class tagging? It's weird that every time I edit a page in the CMS all my styles and jS are killed because of my relative paths. What's going on behind the scenes? Are they making a duplicate copy of my page? Although that still doesn't seem to quite explain it, because forward relative paths such as
/css/style.css will still work,
but relative paths going backward such as
../css/style.css
will no longer work.
Even if they make a duplicate copy, they have FTP access and it seems like they should be able to trace relative paths... Instead they need an absolute or root-relative path.

Relative paths work fine in Surreal, but if your page has include files then the paths may "break" depending on where the page that's including it is located.
Regardless, you can adjust URL formatting pretty easily in Surreal:
<div class="editable" data-urls="absolute">
...
</div>
More details are in the docs: http://www.surrealcms.dev/docs/url-formatting

Related

Absolute path for img and js excluding project folder name Visual Web Dev

I've this little but annoying issue in my project in Visual Web Developer 2010 Express. I'm developing a website with .aspx files located in a large folder structure i.e. www.domain.com/group1/type1/somefile.aspx, the root folder contains a "styles" (for css), "images" and "js" (for javascripts) folder. I've read a lot about base tag, absolute and relative path today. Finally I realized "absolute path" is the best choice for me.
The main problem is that when I preview (locally) my site in browser the absolute links for image, css, and js are not working, I'm using src="/js/gl.jquery.js" which I believe is correct and will work online.
The source code of the page for the javascript says http://localhost:61700/js/gl.jquery.js, when I switch to relative path script src="../../../js/gl.jquery.js" and preview the website, it works fine, and the source code for the javascript path says http://localhost:61700/ProjectName/js/gl.jquery.js (Notice Visual Studio added the ProjectName in the path) So I'm taking my guess that when the project goes online (on a main domain) it will work correctly, but right now I need to keep developing locally without this issue. Is there a way to fix this in Visual Web Developer? maybe some tag for the web.config file that I can remove when goes online, or some website property?
I know a quick solution will be develop with the relative path, and modify the code when goes online to absolute path, but I'm looking for some cleaner method, as aditional information I didn't choose base tag because I read cause troubles with anchors links (href=xx.html#question3) and I need to use them at some big files. And avoid the relative path because it's possible that the company ask me to move some files in the future and I don't wanna be updating relative paths.
Thanks a Lot!
Problem solved! This is the solution I found Thanks to ScottGu's Blog.
I quote the main thing:
when opened a web-site and run the project, VWD launch and run the built-in web-server using a virtual app path that equals the project’s root directory name. For example: if you have a project named “Foo”, it will launch and run in the built-in web-server as http://localhost:1234/Foo/Default.aspx.
One downside to this is that it makes it hard to fully qualify things like static CSS and image files within your site (for example: using root qualified paths like /images/myphoto.jpg or /css/mycss.css). Note that you can use the “~” app path trick for dynamic resources – but static resources still end up being a pain (js, css, images files.) (This was my issue)
Here is the guy entire post: Click Here
Here is the main solution:
1) Using the solution explorer within Visual Studio, select the web-site project node, (the one with the World icon)
2) There is a properties named "Virtual path" at the bottom. Change the "virtual path" setting it to / to run as a root web-site.
And that's it, setting up the / I can manage my files easily.

What's the differences between images/ and ./images/?

In fact, it seems to start both from the current page path.
Its a subtle one which is only relevant if multiple search paths exist (like for executables, see $PATH).
For example, you can start a local executable with ./filename, but not with filename, as the latter makes (most?) shells search in the paths specified by $PATH and not the current working directory.
In a context of URLs, there is no real difference. One should note though, that relative paths are a common attack vector on web applications (escaping the DocumentRoot using ../).
For directories one would imagine nothing. The PATH variable would not come into the picture as a directory is not a command the shell needs to search.
On the side note here is an interesting page to know more about "./" : http://www.linfo.org/dot_slash.html

Absolute paths in PhoneGap

My situation is the following:
I have an index.html and some JavaScript that loads HTML snippets from the server. Inside these snippets, I have some URLs to images like
/some/folder/picture.jpg
Of course these do not work in PhoneGap. Weinre tells me that PhoneGap is trying to load the picture from
file:///some/folder/picture.jpg
Any ideas how to solve this? I was thinking about something like a base href, or some configuration in PhoneGap where one could specify a root path, but I did not find anything like that ...
Thanks,
Michael
I had the same problem especially when you have a lot of views (pages) and want to load one from a menu, yet you are at an unknown location.
The simple work around is to use the window.location object.
window.location.href.split('www')[0] + 'www'
This gives you the absolute URL to your 'base'. The www is the folder which is relevant for IOS and Android, so this also makes your app compatible in multiple platforms.
From this you can use a regular expression which passes the entire doc like jquery mobile does with data-* attributes to describe their elements. You simply replace the regular expression with the path returned. You'll want to do this during initialisation otherwise it will create a massive bottle neck.
Hope this helps and is along the lines of what you're looking for.
Cheers,
Sententia
You can't do that with a <base> because / is always host-relative — it can't be redefined to be in a subdirectory. You have two options:
rewrite your HTML to use fully relative paths like ../../some/folder/picture.jpg (or have something do the rewrite for you as a build step), or
alter the "browser" (PhoneGap's wrapper) so that it loads URLs differently.
I'm not familiar with PhoneGap so I can't comment on automatic options, but I personally would start using relative URLs.

Fitnesse: Open file relative to current page

Is there a simple way to open a file from within a fixture, using a path relative to the current wiki page? The files are actually being stored in the same directory as the wiki page.
I'm using those files to store some expected data, that is later compared to the data actually measured while executing a test. Embedding the data in the wiki page would simply be too much.
I've already spent quite some time searching through the API, but couldn't find anything except how to access files in Fitness' root folder.
It would be simpler to store the files somewhere relative to the FitNesse root and put the relative path on the wiki page
|calculate some results|
|compare to expected at|relativepath|
To create/access pages path relative to the current wiki page use this syntax:
>RelativePage
> makes path relative from current page.

Classic ASP: URL issues when duplicating an application

I have an old Classic ASP application that I want to duplicate in parallel - that is, I want to configure another copy (talking to a different database) alongside the original.
So where I have //MyServer/MyApp1/, I will also soon have //MyServer/MyApp2/... so far so good.
Except that many URLs in the app are absolute (for example JS and CSS files), e.g. <script type="text/javascript" src="/MyApp1/menu.js"></script>.
I could search for references to /MyApp1/ and replace it with /MyApp2/, but it's an annoying task that I will have to repeat as I update the core application, and in the event of wanting other copies creating - a likelihood albeit temporary.
I could change these URLs to parent paths, but this means I need to refer to each resource differently, depending on where in the application folder structure I am. Again, it would work, but I don't like using parent paths for a number of reasons.
Given that there is no tilde (~) feature in Classic ASP (to refer to the application root), are there any alternatives that I can consider?
#CJM: I usually have a db.asp which contains the functions and subs that handle opening/closing database connections as the primary include on practically all of my pages. In this db.asp I would then define a appurl or absurl path which could, in your case, have /MyApp1, and then you can use <script type="text/javascript" src="<%=appurl %>/menu.js"></script> in your scripts.
The first time you do it, it'll be a bit of a search/replace mission, but once it's done, subsequent "duplicate" projects will just need that one variable updated.
In Classic ASP, You can use Server.MapPath("/") to get the root directory, or Server.MapPath(".") to get the current directory.

Resources