OpenCms URLs

(Difference between revisions)
Jump to: navigation, search
m (The effects of URL translation)
m (The effects of URL translation)
Line 39: Line 39:
 
* If this URL is called from the Explorer by clicking on the ''index.jsp'' file in ''/sites/default'', the VFS resource path will be ''/sites/default/index.jsp''.  
 
* If this URL is called from the Explorer by clicking on the ''index.jsp'' file in ''/sites/default'', the VFS resource path will be ''/sites/default/index.jsp''.  
  
* However, if the same URL is called from a browser not logged in to the OpenCms workplace, the constructed VFS resource path will be ''/sites/default/sites/default/index.jsp''. The request will end with HTTP 404 because ''/sites/default'' is the URL configured for the site localhost in opencms-system.xml. The SitePath may not occur in URLs accessed from outside of the workplace.  
+
* If the same URL is called from a browser not logged in to the OpenCms workplace, the constructed VFS resource path will be ''/sites/default/sites/default/index.jsp''. The request will end with HTTP 404 because ''/sites/default'' is the URL configured for the site localhost in opencms-system.xml.
  
 
* The correct external URL for the file ''/sites/default/index.jsp'' therefore is ''http://localhost:8080/opencms/opencms/index.jsp''.
 
* The correct external URL for the file ''/sites/default/index.jsp'' therefore is ''http://localhost:8080/opencms/opencms/index.jsp''.
 +
 +
* Thus, it makes sense to distinguish internal and external URLs: Internal URLs are always absolute VFS pathnames. External URLs are always relative to the configured ''uri'' attribute of the site server that matches the request URL.
  
 
* If you set the ''uri'' attribute of a site in ''opencms-system.xml'' to ''/'', you will expose the complete VFS hierarchy. By not doing so, you can protect parts of the VFS. They will not be accessible from outside the workplace.
 
* If you set the ''uri'' attribute of a site in ''opencms-system.xml'' to ''/'', you will expose the complete VFS hierarchy. By not doing so, you can protect parts of the VFS. They will not be accessible from outside the workplace.

Revision as of 16:42, 30 January 2007

The URL retrieval mechanism in OpenCms can be confusing to new users. When processing a request, OpenCms translates the requested URL to a VFS resource path before delivering the file.

The cause for misunderstanding and trouble is that translation pays attention to the current site of the request. When logged into the workspace the site can be changed with the Site select box at the top of the window. The current site of external requests (from outside the workspace) is determined automatically from the request URL.

Formal URL Syntax

The formal syntax of OpenCms URLs can be written as follows:

OpenCmsUrl ::=    Site ServletPath RequestPath
Site ::=          Protocol "://" Host ":" {Port}
ServletPath ::=   "/" WebappName "/opencms"
RequestPath ::=   SystemPath | ResourcePath
SystemPath ::=    "/system/" ResourcePath
ResourcePath ::=  "/" { [PathCharacter]+ "/"? }*
PathCharacter ::= A valid file or directory name character

Example

Consider a request for the following URL (on a OpenCms default installation):

http://localhost:8080/opencms/opencms/sites/default/index.jsp

opencms-system.xml:

<sites>
  <workplace-server>http://localhost:8080</workplace-server>
  <default-uri>/sites/default</default-uri>
  <site server="http://localhost:8080" uri="/sites/default"/>
</sites>

The above URL is parsed into the following elements:

Site: http://localhost:8080
ServletPath: /opencms/opencms
RequestPath: /sites/default/index.jsp

The Site is matched against the servers defined in opencms-system.xml. The matching site is selected as the current site to serve the request.

In order to finally determine the VFS resource path of the requested file OpenCms adds the uri attribute of the current site in front of the RequestPath unless it is equal to the current site of the browser session.

The effects of URL translation

  • If this URL is called from the Explorer by clicking on the index.jsp file in /sites/default, the VFS resource path will be /sites/default/index.jsp.
  • If the same URL is called from a browser not logged in to the OpenCms workplace, the constructed VFS resource path will be /sites/default/sites/default/index.jsp. The request will end with HTTP 404 because /sites/default is the URL configured for the site localhost in opencms-system.xml.
  • Thus, it makes sense to distinguish internal and external URLs: Internal URLs are always absolute VFS pathnames. External URLs are always relative to the configured uri attribute of the site server that matches the request URL.
  • If you set the uri attribute of a site in opencms-system.xml to /, you will expose the complete VFS hierarchy. By not doing so, you can protect parts of the VFS. They will not be accessible from outside the workplace.
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox