Re: Update Plugin Rewrite Rules

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Update Plugin Rewrite Rules

Claudio Simeone
David House wrote:

> I assume you're adding them directly to the .htaccess file. Don't. Use
> $wp_rewrite. http://codex.wordpress.org/Function_Reference/WP_Rewrite
> and the second example on that page should be able to help you.

I'm sorry if I come back on this topic, but I tried to do as you suggested to me
but I wasn' t able to solve. I want to do this: I create a page
template like this

<?php
/*
Template Name: Pics Template
*/
// and so on...
?>

then I create a Page, with this template an with the slug 'pics'
Now instead of using "mysite.com/pics/?file=mypic"
I want to call this page in this way: "mysite.com/pics/mypic/"
and in the template I want to have the $_GET['file'] with value "mypic".

I tried to add rewrite rules as you suggested to me, but while the url
"mysite.com/pics/" displays the new page, the url
"mysite.com/pics/mypic/" redirects me to the home page.

The original rule was
RewriteRule ^pics/([^/]+)/$ /pics/?mypic=$1 [QSA,L]

I added the rules by a plugin (I'm not sure I understood the mechanism):
<?php
function RTS_pics_rewrite($rewrite) {
global $wp_rewrite;
$keytag_token = '%pics%';
$wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', album=');
$keywords_structure = $wp_rewrite->root . "pics/$keytag_token";
$keywords_rewrite = $wp_rewrite->generate_rewrite_rules($keywords_structure);
return ( $rewrite + $keywords_rewrite );
}
add_filter ('rewrite_rules_array', 'RTS_pics_rewrite');
?>
I tried also with
add_filter ('page_rewrite_rules', 'RTS_pics_rewrite'); and
add_filter ('root_rewrite_rules', 'RTS_pics_rewrite');

Any ideas?
Thanks in advance
--
Mr.Brown
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Update Plugin Rewrite Rules

Jamie Talbot
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mr.Brown wrote:

> I added the rules by a plugin (I'm not sure I understood the mechanism):
> <?php
> function RTS_pics_rewrite($rewrite) {
> global $wp_rewrite;
> $keytag_token = '%pics%';
> $wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', album=');
> $keywords_structure = $wp_rewrite->root . "pics/$keytag_token";
> $keywords_rewrite = $wp_rewrite->generate_rewrite_rules($keywords_structure);
> return ( $rewrite + $keywords_rewrite );
> }
> add_filter ('rewrite_rules_array', 'RTS_pics_rewrite');
> ?>
> I tried also with
> add_filter ('page_rewrite_rules', 'RTS_pics_rewrite'); and
> add_filter ('root_rewrite_rules', 'RTS_pics_rewrite');

add_filter ('rewrite_rules_array', 'RTS_pics_rewrite');

is correct.

>
> Any ideas?

have you also added the ability to recognise the %pics% tag you just added, using the query_vars
filter?  You also might want to not use + to join your two arrays together.  Seeing as the rewrite
rules array can be passed by reference you can just add it that way.  Try this and see if it works:

add_filter('query_vars', 'RTS_query_vars');
add_filter('rewrite_rules_array', 'RTS_pics_rewrite');

// Define the language query variable.
function RTS_query_vars($vars)
{
        $vars[] = 'album';
        return $vars;
}

function RTS_pics_rewrite(& $rewrite)
{
        $keytag_token = '%pics%';
        $wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', album=');
        $keywords_structure = $wp_rewrite->root . "pics/$keytag_token";
        $rewrite[] = $wp_rewrite->generate_rewrite_rules($keywords_structure);
}

Hope this helps, or at least gives you a starting point,

Cheers,

Jamie.

- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFD4kY9rovxfShShFARArdMAJ99B+P68knvMgCUk2zLB4VwDifMEwCbBt0E
cCIS9Si7rSto/HWkFwZhNS0=
=5I1y
-----END PGP SIGNATURE-----
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Update Plugin Rewrite Rules

Claudio Simeone
Jamie Talbot wrote

[cut]

>  Try this and see if it works:
>
> add_filter('query_vars', 'RTS_query_vars');
> add_filter('rewrite_rules_array', 'RTS_pics_rewrite');
>
> // Define the language query variable.
> function RTS_query_vars($vars)
> {
>         $vars[] = 'album';
>         return $vars;
> }
>
> function RTS_pics_rewrite(& $rewrite)
> {
>         $keytag_token = '%pics%';
>         $wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', album=');
>         $keywords_structure = $wp_rewrite->root . "pics/$keytag_token";
>         $rewrite[] = $wp_rewrite->generate_rewrite_rules($keywords_structure);
> }
>
> Hope this helps, or at least gives you a starting point,

Thanks for the answer, but unfortunately it doesn't work. At this
point I have no ideas... I tried also the other example on the Codex
:-(

I try to semplify the question: it is possible in 2.0.1 to pass a
variable to a Page in this way
mysite.com/page-slug/var/ ???
It is possible using rewrite rules? And in which way it is possible?

Thanks again
Mr.Brown
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Update Plugin Rewrite Rules

Jamie Talbot
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mr.Brown wrote:
> I try to semplify the question: it is possible in 2.0.1 to pass a
> variable to a Page in this way
> mysite.com/page-slug/var/ ???
> It is possible using rewrite rules? And in which way it is possible?

Yes, it is possible:

I can't explain it much more but you can see a demonstration here:

http://dev.wp-plugins.org/file/gengo/trunk/gengo/gengo.php

Look at the constructor which adds the filters, and the functions rewrite_rules() and query_vars();

Basically, I do exactly the same as that demo code, which works for me.  I'm not sure why it's not
working for you, sorry.

Good luck,

Jamie.

- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFD4q/ErovxfShShFARAh3dAJ41h/5oFZG9SIudEUOiw08rBcoaEwCeOM7C
C11rpzuzjWMYbrVMG6NrZs4=
=1O9E
-----END PGP SIGNATURE-----
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Update Plugin Rewrite Rules

Claudio Simeone
Jamie Talbot wrote

[cut]

> I can't explain it much more but you can see a demonstration here:
> http://dev.wp-plugins.org/file/gengo/trunk/gengo/gengo.php

[cut]

Thanks Jamie, I tried also with your plugin examples but didn't work.
But I found this example here
www.fabriziotarizzo.org/cache/query_redirect_rewrite.phps
and now works :-)

Thanks again
:-)
--
Mr.Brown
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...