Topic: rewrite rules

I am trying to make for my extension gallery the sef urls but I am lost, can somebody help me a little?
I am trying this for the last 5 days but i still do not get it, what am I doin wrong!

rewrite_rules.php

<?

$pun_rewrite_rules_gallery = array(
  '/^gallery(\.html)?$/i'                             => 'index.php?gallery',
  '/^gallery_album[\/_-]?([0-9]+).*(\.html?|\/)?$/i'  => 'index.php?gallery&album=$1'
);

$pun_rewrite_rules = array_merge($pun_rewrite_rules, $pun_rewrite_rules_gallery);

Default.php

<?php

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
  exit;

$pun_url_gallery = array(
  'gallery'       => 'index.php?gallery',
  'gallery_album' => 'index.php?gallery&album=$1'
);

$pun_url = array_merge($pun_url, $pun_url_gallery);

File_based.php

<?php

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
  exit;

$pun_url_gallery = array(
  'gallery'       => 'gallery.html',
  'gallery_album' => 'index.html?gallery&album=$1'
);

$pun_url = array_merge($pun_url, $pun_url_gallery);

File_based_(fancy).php

<?php

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
  exit;

$pun_url_gallery = array(
  'gallery'        => 'gallery.html',
  'gallery/album/'  => 'gallery/album_$1.html'
);

$pun_url = array_merge($pun_url, $pun_url_gallery);

Folder_based.php

<?php

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
  exit;

$pun_url_gallery = array(
  'gallery'        => 'gallery',
  'gallery_album'  => 'gallery/album/$1'
);

$pun_url = array_merge($pun_url, $pun_url_gallery);

and the code i use to print my url is:

pun_link ( $pun_url['gallery_album'], array($li_gallery_name, sef_friendly ( $li_gallery_name ) ) )

2 (edited by daris 2008-02-29 14:45)

Re: rewrite rules

Did you load this files via hooks?

Is it copied/replaced from my portal extension? big_smile

Re: rewrite rules

yes I did, I copied it from your extension roll

but can you tell me what I am doing wrong?

4 (edited by daris 2008-02-29 16:18)

Re: rewrite rules

Have you got in your manifest.xml something like this?

        <hook id="re_rewrite_rules"><![CDATA[
require PUN_ROOT.'extensions/portal/include/rewrite_rules.php';
]]></hook>
        <hook id="co_common"><![CDATA[
$portal_dir = PUN_ROOT.'extensions/portal/';

// Setup the URL rewriting scheme
if (file_exists($portal_dir.'include/url/'.$pun_config['o_sef'].'.php'))
    require $portal_dir.'include/url/'.$pun_config['o_sef'].'.php';
else
    require $portal_dir.'include/url/Default.php';
]]></hook>

Also you can debug some information using print_r($array) php function

Re: rewrite rules

I got this:

<hook id="co_common">
      <![CDATA[
        // Setup the URL rewriting scheme
        if ( file_exists ( PUN_ROOT.'extensions/gallery/include/url/'.$pun_config['o_sef'].'.php' ) ) {
          require PUN_ROOT.'extensions/gallery/include/url/'.$pun_config['o_sef'].'.php';
        } else {
          require PUN_ROOT.'extensions/gallery/include/url/Default.php';
        }
      ]]>
    </hook>
    <hook id="re_rewrite_rules">
      <![CDATA[
        require PUN_ROOT.'extensions/gallery/include/rewrite_rules.php';
      ]]>
    </hook>

Re: rewrite rules

Can someone tell me what i did wrong sad

7

Re: rewrite rules

What do you get when you type on address bar:

{path to your forum}/gallery.html

8 (edited by kierownik 2008-03-01 10:27)

Re: rewrite rules

then I get a bunch of error with underneath my gallery.

http://pundemo.kierownik.nl/gallery.html

Notice: Undefined offset: 1 in /home/kierowni/public_html/pundemo/rewrite.php on line 68

Notice: Undefined offset: 1 in /home/kierowni/public_html/pundemo/rewrite.php on line 70

Warning: Cannot modify header information - headers already sent by (output started at /home/kierowni/public_html/pundemo/rewrite.php:68) in /home/kierowni/public_html/pundemo/header.php on line 31

Warning: Cannot modify header information - headers already sent by (output started at /home/kierowni/public_html/pundemo/rewrite.php:68) in /home/kierowni/public_html/pundemo/header.php on line 32

Warning: Cannot modify header information - headers already sent by (output started at /home/kierowni/public_html/pundemo/rewrite.php:68) in /home/kierowni/public_html/pundemo/header.php on line 33

Warning: Cannot modify header information - headers already sent by (output started at /home/kierowni/public_html/pundemo/rewrite.php:68) in /home/kierowni/public_html/pundemo/header.php on line 34

Warning: Cannot modify header information - headers already sent by (output started at /home/kierowni/public_html/pundemo/rewrite.php:68) in /home/kierowni/public_html/pundemo/header.php on line 37

9 (edited by daris 2008-03-01 10:48)

Re: rewrite rules

PunBB rewrite_rules.php srcipt searches "=" in url so replace:

'/^gallery(\.html)?$/i'                             => 'index.php?gallery',

with

'/^gallery(\.html)?$/i'                             => 'index.php?gallery=',

in rewrite_rules.php

Re: rewrite rules

that works smile thanks
but when going to an album I get the error Bad Request hmm sad

11

Re: rewrite rules

Also same as above replace:

'/^gallery_album[\/_-]?([0-9]+).*(\.html?|\/)?$/i'  => 'index.php?gallery&album=$1'

with

'/^gallery_album[\/_-]?([0-9]+).*(\.html?|\/)?$/i'  => 'index.php?gallery=&album=$1'

Re: rewrite rules

I did that but it did not make any difference sad

13

Re: rewrite rules

Try this:

'/^gallery_album[\/_-]?(.*)(\.html?|\/)?$/i'  => 'index.php?gallery=&album=$1'

Re: rewrite rules

I did that to daris but I still get Bad request hmm

The gallery.html is working great in every thing ( Default, filebased etc)

I do not get why the album is not working.

Thanks for helping me daris smile

15

Re: rewrite rules

Maybe this?

'/^gallery_album[\/_-]?(.*?)(\.html?|\/)?$/i'  => 'gallery.php?album=$1'

Re: rewrite rules

Nope does not work either sad

I am getting frustrated hmm

even http://www.ilovejackdaniels.com/mod_rew … _sheet.pdf does not help me sad

Re: rewrite rules

You're defining some pun_url stuff as gallery_album and some as gallery/album/. You should be using the same indexes (the first one) no matter what.
And the other issue is one we should probably address in the core, I'll be doing that now.

Re: rewrite rules

yes I saw that too Smartys and I changed that but that does not make any difference.

I am wondering what the Bad request means hmm

Re: rewrite rules

Fixed, you should now be able to pass script.php?foo without a notice.
Bad request means you didn't match any of the rewrite rules.

Re: rewrite rules

Can you tell me what I am doing wrong Smartys?

Re: rewrite rules

Try using the latest SVN. If it still doesn't work, repost all the code you're using now in your extension.

Re: rewrite rules

Latest SVN = 1537

rewrite_rules.php

<?php

$pun_rewrite_rules_gallery = array(
  '/^gallery(\.html)?$/i'                             => 'index.php?gallery',
  '/^gallery_album[\/_-]?([0-9]+).*(\.html?|\/)?$/i'  => 'index.php?gallery?album=$1'
);

$pun_rewrite_rules = array_merge($pun_rewrite_rules, $pun_rewrite_rules_gallery);

Default.php

<?php

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
  exit;

$pun_url_gallery = array(
  'gallery'       => 'index.php?gallery',
  'gallery_album' => 'index.php?gallery&album=$1'
);

$pun_url = array_merge($pun_url, $pun_url_gallery);

File_based.php

<?php

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
  exit;

$pun_url_gallery = array(
  'gallery'       => 'gallery.html',
  'gallery_album' => 'gallery.html&album=$1'
);

$pun_url = array_merge($pun_url, $pun_url_gallery);

File_based_(fancy).php

<?php

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
  exit;

$pun_url_gallery = array(
  'gallery'         => 'gallery.html',
  'gallery_album'  => 'gallery/album_$1.html'
);

$pun_url = array_merge($pun_url, $pun_url_gallery);

Folder_based.php

<?php

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
  exit;

$pun_url_gallery = array(
  'gallery'        => 'gallery',
  'gallery_album'  => 'gallery/album/$1'
);

$pun_url = array_merge($pun_url, $pun_url_gallery);
echo "<li class=\"topactive\"><a href=\"".pun_link ( $pun_url['gallery_album'], array($li_gallery_name, sef_friendly ( $li_gallery_name ) ) )."\"><span>".htmlentities ( $dir )."</span></a></li>";

and $li_gallery_name gives the &_GET['album']

Re: rewrite rules

And what is the problem you're having?

Re: rewrite rules

Aha
http://pundemo.kierownik.nl/gallery.htm … m=Lightbox
You shouldn't be adding arbitrary elements to the URL. You should be using pun_link for that.

Re: rewrite rules

searched the web about arbitrary elements but could not find any good explanation for it in my language so I used http://babelfish.altavista.com/tr that tells me that arbitrary elements are random elements. What I am then asking myself is, what elements.

I know that everyting looks like I want to, so too how the links should look like e.g. gallery/album/Lightbox but then after clicking I get the Bad request.

I think my mistake is in the line:
  '/^gallery_album[\/_-]?([0-9]+).*(\.html?|\/)?$/i'  => 'index.php?gallery?album=$1'