URL Rewrite for page number

alipatov

Joined: 2006-05-09
Posts: 8
Posted: Tue, 2006-05-09 22:59

Hi, I'm not sure it's the right forum, but here goes -

Currently URL Rewrite module does not support page keyword making all pages >1 into links with &g2_page=2.

I'm proposing a simple addition -

1. Add

'page' => array(
'pattern' => '([0-9]*)',
'help' => $this->translate('Page number)'),
'function' => array('rewrite', 'RewriteSimpleHelper', 'parsePage')),

to getRewriteRules() in module.inc for Show Item

2. Add

function parsePage(&$url, &$params, &$entity) {
$url = str_replace('%page%', $params['page'], $url);
unset($params['page']);
return true;
}

function to RewriteSimpleHelper.class

And voila! Go to your site admin and add %page% to the Show Item link, for instance - /%path%/%page%

The rewrite pattern ([0-9]*) ensures that links without page numbers work fine too.

The only downside to this that I have not been able to figure out so far, is that all permalinks for the first page must have a "/" at the end.

Thanks!
Art

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2006-05-10 02:41

This is a great start! In parsePage I did $page = isset($params['page']) ? $params['page'] : ''; and used $page in the str_replace.. with that it works as you describe. There are a few things to think about before adding this in...

  • Non-albums are affected.. %path% -> myalbum/myimg.jpg.html --- %path%/%page% -> myalbum/myimg.jpg/
  • You could name an album "2".. myalbum/subalbum/2 is then page 2 of subalbum, myalbum/subalbum/2/ is album called "2" inside subalbum.. confusing, but only people who use numeric album path components need to understand this.

The second one maybe is ok.. for the first one, can we find a way to make non-albums work as before?

 
alipatov

Joined: 2006-05-09
Posts: 8
Posted: Wed, 2006-05-10 12:19

Yes, I thought about it and I think it should be done with minimal impact on existing configurations... However I lacked knowledge to do that on my own :)

- Non albums could be excluded from the logic altogether. is it possible to determine whether the entity is an album or a photo?

I think I'm answering my own question - $entity->entityType will tell whether to perform the translation or not. Note, that this might be a weak point of this function because we will miss or misuse the new types added at a later date

- It is a problem for people who already bookmarked specific albums.

Solution 1: change the rewrite pattern to make the / at the end optional (no idea how at this moment).

Pros:
- existing links work exactly like before

Cons:
- albums cannot have numeric names

Solution 2: leave the way it is

Pros:
- links are consistent - the ones with a '/' at the end are album's first page
- does not matter what albums are called

Cons:
- existing bookmarks are not working anymore

This way or another we're going to have to bite the bullet and screw up some users in order to please the others :)

Or, make this configurable so users may choose

Thanks!
Art

 
alipatov

Joined: 2006-05-09
Posts: 8
Posted: Wed, 2006-05-10 12:21

Just realized -

Since non-albums are processed with the same URL it would not be possible to just exclude them, the / at the end needs to be made optional in the rewrite rule..................

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2006-05-10 16:56

This %page% token is tricky because it is optional.. I wonder if we could use 2 rewrite rules, like this:

  RewriteCond %{THE_REQUEST} \ /gallery2/v/([^?]+)/([0-9]+)(\?.|\ .)
  RewriteCond %{REQUEST_URI} !/gallery2/main\.php$
  RewriteRule .   /gallery2/main.php?g2_view=core.ShowItem&g2_path=%1&g2_page=%2   [QSA,L]

  RewriteCond %{THE_REQUEST} \ /gallery2/v/([^?]+)(\?.|\ .)
  RewriteCond %{REQUEST_URI} !/gallery2/main\.php$
  RewriteRule .   /gallery2/main.php?g2_view=core.ShowItem&g2_path=%1   [QSA,L]

I'm not sure how to get URL rewrite module to write that, but if it could, would this work?
Note I changed [0-9]* to [0-9]+ in the first rule, so this one only matches when there IS a page number.
Seems like this could work for v/%path%/%page% .. what if someone did some other pattern like %page%::%path% or %path%@page%page% ? How could we parse these patterns into the approprite rules? ie, since %page% is optional, how do we know what to strip out of the pattern for the 2nd rule... for %path%/%page% we stripped the / before %page%

 
alipatov

Joined: 2006-05-09
Posts: 8
Posted: Wed, 2006-05-10 18:31

i just tried, it does not seem possible to have two rewrite rules here. Rewrite admin does not allow to have two urls pointing to the same view (nor would I expect it to). If we really need the separation of album view and photo view we will also need it on the Gallery API level. At this point it's just one - ShowItem

also, we cannot strip anything exactly because the path may be completely different.
it looks like if %page% is optional the only way to have it is at the end of the url after a '/' or a '#' (the latter is not very good since I'm pretty sure search engines will ignore it)

i give up.

The modification I made with %page% and ([0-9]*) is suitable for me and, I'm sure, will be good enough for many users. Yes, the links will change, and some users will not want that so they won't do it. I really don't see any other solution at this point

Thanks!
Art

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2006-05-11 22:50

agreed, doesn't seem trivial to keep the non-album links as they were.
and, since we don't use this token by default it seems ok to put it in, and those that want it can use it as is... it's in svn now, give it a try!

 
AmsPics

Joined: 2006-04-15
Posts: 8
Posted: Mon, 2006-06-19 17:01

Hello,
I have problems making it work. I've added:

$rules[0] = array(
'comment' => $this->translate('Show Item'),
'match' => array('view' => 'core.ShowItem'),
'pattern' => 'v/%path%',
'keywords' => array(
'path' => array(
'pattern' => '([^?]+)',
'help' => $this->translate('Path to an item (eg, /album/image.jpg.html)'),
'function' => array('rewrite', 'RewriteSimpleHelper', 'parsePath')),
'page' => array(
'pattern' => '([0-9]*)',
'help' => $this->translate('Page number)'),
'function' => array('rewrite', 'RewriteSimpleHelper', 'parsePage')),
'language' => array(
'pattern' => '([a-z]{2}|[a-z]{2}_[A-Z]{2})',
'help' => $this->translate('Current language (eg, en or de)'),
'function' => array('rewrite', 'RewriteSimpleHelper', 'parseLanguage'))),
'onLoad' => array('rewrite', 'RewriteSimpleHelper', 'loadItemIdFromPath'),
'help' => $this->translate('The general URL for viewing items.'));
to module.inc

And I've added:

function parsePage(&$url, &$params, &$entity) {
$url = str_replace('%page%', $params['page'], $url);
unset($params['page']);
return true;
}

to RewriteSimpleHelper.class but it still does not works.

I get a
An error occured while trying to save your settings
Bad keyword.

Please advice,
Thanx.

 
AmsPics

Joined: 2006-04-15
Posts: 8
Posted: Mon, 2006-06-19 23:11

Well,
I've managed to make it work. The only problem is that the URL is:
domain.com/gallery2/album/picture_name.jpg/

Spent a few hours trying to move the "page" rule to anothere category but I was unable to make the / dissapear. There are so many flaws from search engine point of view. Lots of things needs to be taken care off before it will be trully search engine friendly.

PLease tell me if anyone find a sollution for making the URL domain.com/gallery2/album/picture_name.html and still keep the "page" option. I've tryed to make 2 rules on core.ShowItem but i was not able.

Thanx.

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Sun, 2006-09-24 18:47

I edited module.inc. and RewriteSimpleHelper.class according to these instructions and placed them in local directories in the URL rewrite module, but when I went to change /%path%/%page% in ShowItem I get an error that says "Bad Keyword"...do I have to deactivate and reactivate the module to get this to work? I am eager to resolve the problems with the page number nav on my site. Thanks!

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2006-09-24 23:22

no need to hack it.
see the message from mindless. it's in svn (our development repository / version) now.

you can upgrade to the latest nightly snapshot to get that feature.
in site admin -> rewrite, you can then use the "%page%" placeholder in the ShowItem rule.

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Mon, 2006-09-25 19:38

Do I have to upgrade to 2.2 before getting it from SVN?

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Mon, 2006-09-25 19:48

I tried installing the tortoise SVN app as i am on Windows...both the latest and an older version wouldn't install. I don't have unix shell access but I might be able to get my hosting TS to do it. Do I need to upgrade though?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2006-09-25 20:02

just use the nightly snapshots, no need to use svn.
see the download page for nightly snapshots.

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Tue, 2006-09-26 18:29

ok...do I have to install ALL the files in nightly snapshot or can I just overwrite my current rewrite module files with the new ones from the snapshot? Also, should I deactivate the module first? Thanks!

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Tue, 2006-09-26 22:10

I tried just overwriting the URL rewrite module..got a version mismatch error...full upgrade it is

 
LFrank

Joined: 2005-02-19
Posts: 1023
Posted: Wed, 2006-09-27 11:42

ichtyous,
just wanted to answer 'all' ;)

Gallery version = 2.2-svn core 1.1.16
PHP version = 5.1.6 apache2handler
Webserver = Apache/2.2.3 (Win32) DAV/2 PHP/5.1.6 mod_ssl/2.2.3 OpenSSL/0.9.8c
Database = mysql 5.1.11 beta-log,
Theme=PGlightbox,
Gallery-URL=http://lf-photodesign.de

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Wed, 2006-09-27 19:06

Lutz,

I installed your version and have it running now. The latest version of gallery 2.2 has included the page number fix...but it apparently it has a small glitch. For whatever reason, in galleries where I have the album theme set to display 2 columns and 3 rows (which is my default) and there are over 7 pages of items...the number 7 is repeated twice in the bottom page numer nav! One of them is a link and the other one is static, and it only happens with 7....take a look here for instance:

Landscape photos

Washington DC photos

 
robert070612

Joined: 2003-08-05
Posts: 565
Posted: Wed, 2006-09-27 19:29

ichthyous----
You've got it hardcoded I think.
Search your template tree for the character sequence:
</a>7</a>
----best wishes, Robert

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Wed, 2006-09-27 21:20

what template is the page number nav in? Is that album.tpl?

 
robert070612

Joined: 2003-08-05
Posts: 565
Posted: Wed, 2006-09-27 22:20

ichthyous----
It is in my own site's template...

{* Navigator *}{* ----------------------------------------------- *}

{if $theme.totalPages > 1}
    <div class="refresh-right">
      {g->text text="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;an on-site Ctrl-F5 refreshes 'empty' pictures"}
    </div>
  {g->block type="core.Navigator" navigator=$theme.navigator prefix="&laquo;" suffix="&raquo;" currentPage=$theme.currentPage totalPages=$theme.totalPages}
    {if !empty($theme.jumpRange)}
      <div id="gsPages" class="gbBlock gcBackground1">
        {g->block type="core.Pager"}
      </div>
    {/if}
{else}
  {if !empty($theme.parents)}
    <div class="refresh-right">
      {g->text text="an on-site Ctrl-F5 refreshes 'empty' pictures"}
    </div>
  {/if}
{/if}

...the "core.Pager" calls up the magic...
/modules/core/templates/blocks/local/Pager.tpl

So, it looks like you've got a small edit in the core to correct?

----best wishes, Robert

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Sun, 2007-11-25 21:22

I opened up pager.tpl and I didn't see anything wrong...strange. Does anyone know where something like this could be coming from?

 
robert070612

Joined: 2003-08-05
Posts: 565
Posted: Thu, 2006-09-28 10:12

ichthyous----
I'm curious please upload your...
/modules/core/templates/blocks/Pager.tpl
/modules/core/templates/blocks/local/Pager.tpl
...files to the forum.
----best wishes, Robert

 
ichthyous

Joined: 2006-06-16
Posts: 324
Posted: Sun, 2007-11-25 21:28

Hello, I am wondering how to resolve one issue with the page number rewrites. The page numbering causes duplicate content pages, for example:

http://andrewprokos.com/photos/architecture/
http://andrewprokos.com/photos/architecture/1

These are both the same page, which would be seen as dupe content by the search engines. The second url is referred to by all the page number links. I tried to merge them using url rewrite and 301 redirect in htaccess, but these never work with gallery urls for some reason. Is there a way to set the pager to start at page 2 and skip page #1 altogether? Thanks!

 
mridgwel

Joined: 2007-01-27
Posts: 215
Posted: Wed, 2007-12-12 01:25

I've got this working for the standard albums, but not for the dynamic albums.

Does this need to be changed in every dynamic album too?

Ideally I'd like to be able to do www.example.com/key/Foo/274 to get page 274 of the Foo keyword list. when I tried to add %page% to the keyword it wouldn't accept the url rewrite specification

 
mridgwel

Joined: 2007-01-27
Posts: 215
Posted: Wed, 2007-12-12 01:44

Ok, I'll reply to my own question ;-)

I've experimented with the keyword dynamic album and managed to get this to work.

Is anyone working on the changes for the dynamic albums? If not I'm happy to post changes/diff's for the ones that I use ( URL, Rating, Dynaimc albums [updates, popular, random] )

This is also probably the wrong place to ask, but is there any reason why the downloadItem can't support the Path to the item e.g:

instead of:

d/%itemId%/%serialNumber%/%fileName%

being able to specify:

d/%path%/%serialNumber%/%fileName%

 
mridgwel

Joined: 2007-01-27
Posts: 215
Posted: Fri, 2007-12-14 00:54

If you want to change the keyword album so it supports the same format /key/%keyword%/%page% then in module.inc change the function getRewriteRules() as below:

/**
* @see GalleryModule::getRewriteRules
*/
function getRewriteRules() {
return array(
array('comment' => $this->translate('Keyword Album'),
'match' => array('view' => 'keyalbum.KeywordAlbum'),
'pattern' => 'key/%keyword%/%page%',
'help' => $this->translate('Short URL for Keyword Albums'),
'keywords' => array(
'keyword' => array('pattern' => '([^?/]+)',
'help' => $this->translate('Keyword to use for dynamic album')),
'page' => array('pattern' => '([0-9]*)',
'help' => $this->translate('Page number in a dynamic album')) )
));

 
micrafty

Joined: 2007-12-27
Posts: 53
Posted: Wed, 2008-01-02 05:10
Quote:
no need to hack it.
see the message from mindless. it's in svn (our development repository / version) now.

you can upgrade to the latest nightly snapshot to get that feature.
in site admin -> rewrite, you can then use the "%page%" placeholder in the ShowItem rule.

Gee, this worked swell. Changed the ShowItem to %page% and every album goes back to the homepage. It wouldn't let me change it back to %path%, every time I do it just takes me back to main.php and doesn't make the change. Oh yes, main.php is back after I finally got rid of that too.

Uninstalled the plugin thinking that would allow me to edit it. Reinstalled and still had a mess. Then I made the ultimate mistake of deleting the plugin hoping to clear things - only problem was all the changes I've made all today to clean up all the other URL problems are still in place and now the plug in will not even download properly.

Would love to hear any suggestions other than starting completely over. And would someone please explain why this is still an issue in the first place? Sheesh. From what I've seen in the forums today, this has been a problem since 2005. Why not fix the URLs properly and be done with it? Not a happy camper right now.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2008-01-02 13:08

@micrafty:
> I've seen in the forums today, this has been a problem since 2005.

what? the short URL part for pages? the first official release with this functionality has been released in 2007 (Gallery 2.2).

> Why not fix the URLs properly and be done with it?

works for me.

please don't cross post. let's continue your case in the thread that you've started in the support forum.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
pavel.pola

Joined: 2007-05-19
Posts: 30
Posted: Wed, 2008-05-28 09:58

Hello, I've switched on rewriting for page number but it seems it is working only INSIDE albums (is't not working on the home page). Does anybody know what's wrong?

Example:
http://www.pavelpola.cz/?g2_page=2 (wrong)
http://www.pavelpola.cz/foto/sumava-na-kolech/2 (correct)

_________________________________
Please visit my personal gallery: http://www.pavelpola.cz (mostly B&W pictures, Prague, nature, people)

 
fANDa

Joined: 2008-10-13
Posts: 3
Posted: Mon, 2008-10-27 12:52
pavel.pola wrote:
Hello, I've switched on rewriting for page number but it seems it is working only INSIDE albums (is't not working on the home page). Does anybody know what's wrong?

Example:
http://www.pavelpola.cz/?g2_page=2 (wrong)
http://www.pavelpola.cz/foto/sumava-na-kolech/2 (correct)

I have same problem.
pavel.pola's describtion is better then my in http://gallery.menalto.com/node/81643#comment-288881

Please, how can I fix it?

 
mridgwel

Joined: 2007-01-27
Posts: 215
Posted: Mon, 2008-10-27 20:26

I'm pretty sure this is a limitation of the URL rewrite rules, just like the first page isn't always correct. - I think I had the same problem at one point but I've since removed a most things from the root album pending a re-organization.

_________
Mark

 
Carvehicle.net

Joined: 2008-12-27
Posts: 28
Posted: Wed, 2008-12-31 17:09

Thanks for topic