Gallery:模块:永久链接(permalinks)

来自站长百科
跳转至: 导航、​ 搜索

Permalinks Module

Use permanent links (URLs) as addresses for your albums and items.

Description

One of the nice and bad aspects of G1 was that the namespace of albums was flat: you couldn't have two albums named the same within the same gallery. G2, with its truly hierarchical albums, fixes this, at the expense of those nice short descriptive URLs: URLs in G2 are either very long or meaningless (with the rewrite module).

Example of an original URL:

http://www.example.com/gallery2/main.php?g2_itemId=5471

Example of a normal short URL:

http://www.example.com/gallery2/v/Countries/Switzerland/Zurich.html

With Permalinks, you can have the best of both worlds: short descriptive URLs for some of your albums (and even any other item) which have the added benefit of not changing if you move an album into a different parent album.

Example of a permalink URL:

http://www.example.com/gallery2/f/Zurich

Usage

  • Install and activate URL Rewrite rule
  • Install and activate the permalinks module
  • Activate the permalink rule in Site admin -> URL rewrite.
  • Add/delete permalinks for items in General tab of "Edit Item" / "Edit Album" / "Edit Photo."
  • Optional: Turn on auto-permalink creation and delete existing permalinks in Site Admin -> Permalinks.

After activating the module, you need to enable the corresponding URL Rewrite (the URL Rewrite module also needs to be enabled, using either "Apache mod_rewrite" or "PHP pathinfo"). Once that's done, you can define a Permalink for any item in that item's edit interface. You can then access the item using a short URL that doesn't depend on the item's location, like (if using the "Apache mod_rewrite" option)

http://www.example.com/gallery2/f/myitem

or (if using the "PHP pathinfo" option)

http://www.example.com/gallery2/main.php/f/myitem

Some more explanation:

  • Check directory /etc/apache2/mods-enabled/ for the mod_rewrite module to be loaded. This is preferred over php_pathinfo.
  • Log in Gallery2 with an administrator account and click Site Admin, then Modules, and check for a Green Cross at module Permalinks. If you see a Red Cross instead, click this module's name and follow instructions.
  • The instructions suggest to create a world-writable file /usr/share/gallery2/.htaccess, but it seems more secure to me to set the group to that which Apache uses to run under, and to give it a chmod 660. Gallery2 will accept this.
  • After activation, Gallery2 will write an impressive apache Url Rewrite section to this .htaccess file, sign that "it works".
  • Either set a permalink to an individual album by clicking Edit Album, or enable Auto-Permalinks in Site Admin, Permalinks.

Now by clicking an album that has a permalink set, you will see the new, meaningful URL in the location field of your web browser.