Path

ez.no / ezpublish / documentation / customization / tips & tricks / creating nice urls


Creating nice URLs

These documentation pages are no longer maintained. Please visit the new documentation site.

What are nice urls?

Well, take a look at the ez.no site and you will notice that the URL's are formed with a nice descriptive path and without the index.php and /content/view/full/id like in the demo setup.

Why doesn't the demo come with these nice urls?

The demo setup is general for both non-virtual host and virtual host setups. Therefore it always includes the index.php script.

What are the necessary steps to get rid of index.php in the URL?

First of all, you need to have a virtual host based setup with the proper rewrite rules. See the install section for a detailed description.

Then you need to search for instances of the ezurl operator in the templates and change it to ezroot instead. The latter does not include the index.php in the resulting URL. If you create your own templates, just use ezroot for URL assembling.

How to get a nice path representation in the URL?

First you need to change NodeTranslation in [URLTranslator] to enabled in your /settings/override/site.ini.append.php or in the siteaccess override for your /settings/siteaccess/yoursite/site.ini.append:

[URLTranslator]

# Use either enabled or disabled

Translation=enabled

# Enable this if you want to percieve the url as a path element

# for the node tree. By entering the path in the url and ending it

# with a .html you will get the correct node.

NodeTranslation=enabled

The next step is to change your templates to use the url_alias field for the requested node in actions like /content/view/full in the build up of urls (and use the ezroot operator instead of the foul-proof ezurl operator if you did not already do this).

For example change

<a href={concat("/content/view/full/",$Folder:item.node_id,"/")|ezurl}>{$Folder:item.name|wash}</a>

to

<a href={concat("/",$Folder:item.url_alias)|ezroot}>{$Folder:item.name|wash}</a>

As always when changing templates, clear your cache to see the results or turn off caching altogether.

Where to use nice urls?

You can use nice urls with url_alias in all instances where you have a /content/view action. So pagelayout.tpl and the overrides for sections are the place to start. Next you can change the overrides for the full_class_[id] for folder or folder like objects.

Where not to use nice urls?

Better not use the url_alias in actions other than

/content/view/<full|list...>

since you may break some functionality in for example creating new objects (where url_alias does not make sense since the node has no name yet).

Comments

About 'nice URL's'

I want eZ shows actually names of folders as urls.
But it shows the titles of site pages in translite from russian into english.

What I've done wrong?
Please. Help. :)

re:nice url to subfolder does'n work

rombeh rorombeheun
just add following lines to .htaccess:
RewriteEngine On
RewriteRule ^([^.]+)/?$ /index.php/$1

see final look (Once again)

nice url to subfolder does'n work

follow yours, I add following lines to .htaccess:
RewriteEngine On
RewriteRule ^([^./]+)/?$ /index.php/$1

it's work when I access url aliases point root subdirectory (ex: www.site.com/news), but when I try to access next directory level (www.site.com/news/thisnews) the system can't find the page.

any help...?
thanks

broken link


the link (in the article) to the install section doesn't work anymore

Don't forget to change ezurl to ezroot for link tags

When changing ezurl to ezroot, you'll also want to change it for <link> tags inside of XML text fields. To do this, override the template /design/standard/templates/content/datatype/view/ezxmltags/link.tpl and change:

<a href={$href|ezurl} {section show=$target}target="{$target}"{/section}>{$content}</a>

to

<a href={$href|ezroot} {section show=$target}target="{$target}"{/section}>{$content}</a>

(This example based on 3.3-4 ... if you have a different version your link.tpl might be slightly different.)

Once again

I found a typo again, here's its final look:
---
RewriteEngine On
RewriteRule ^([^.]+)?$ /index.php/$1
---

Sorry

Sorry, I made a type, '.htaccess' should look like this:
---
RewriteEngine On
RewriteRule ^([^./]+)?$ /index.php/$1
---

mod_rewrite

As it was said, to get rid of 'index.php' in URL's you should put 'ezroot' in your eZ links instead of 'ezurl' but you also should put the .htaccess' file with the following content:
---
RewriteEngine On
RewriteRule ^([^./]+)/?$ /index.php/$1
---

Contents

Customization

Access control
eZ publish API Documentation
Content structure
Custom design
Components
Tips & Tricks
    Debugging templates
    Javascript in templates
    Fetching current user
    Showing related objects
    Show which templates are used
    Fetching the ID of the parent
    One Article Folder
    Creating tree menus
    How can I use my own php script insid...
    Hiding attribute content
    Splitting an article over several pages
    Accessing section id in pagelayout
    List articles in folder
    Creating nice URLs
    Alt tag on images
    Improve the pagelayout.tpl
    Clean HTML tags
    Insert javascript call inside ezpub d...
    3rd party applications
    Fetch Function examples
    Display more than 15 items on your co...
    Including PHP files in templates
    Redirecting after content publishing
    HowTo see if article has an image
    Date and Time Formats
    Forms processing example: store user...
    Adjust Timezone
    Adding a Remove Button/Image
    Find the age in years for an object
    Editing, creating and removing conten...
    Indexing binary files with IFilters o...
Troubleshooting


Created

08/05/2003
10:02:41 pm
by Paul Borgermans

Last updated

15/09/2003
11:18:35 am
by Gunnstein Lye

Authors

Paul Borgermans
Bård Farstad
Gunnstein Lye



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.