custom dinamically generated (sub)pages

Hi All,

I have a a custom wp page with the following slug: /artist

In that page, I'd like to catch the rest of url to manage it as a normal parameter for the same page.

For example:

where "foo" isn't a page, but a simple parameter of the "artist" page. I know that mod_rewrite could be a friend of mine, but I don't know how to do.

To sum up, I'd like to have just ONE page, that takes in input the rest of URL as a parameter.

Any hints, any suggetions?

thanks in advance!

  • Emiliano
    • WPMU DEV Initiate

    David, Ulrich,
    thanks for your replies!

    David, your link is interesting, but I'm not able to setup a working example of redirecting. Ulrich, I tried to add your line into my .htaccess without success. :slight_frown:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteRule ^artist/(.+) artist/ [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress

    If if go to
    I received a 404 error, with the only WP page "artist".

    What am I missing?

  • drmike
    • DEV MAN’s Mascot

    You have to put it separate within your htaccees file, not mixed in with the wordpress rules.

    The problem though is if you do this as a rewrite within your htaccess file, you're doing this redirect for all of your sites/blogs on your install.

    Have to think about this....

  • Emiliano
    • WPMU DEV Initiate

    Just to shall you know how I resolved this issue, hoping to help anyone :slight_smile:
    I've just added the following lines into my function.php:

    add_action( 'init', 'wpa5413_init' );
    function wpa5413_init()
        // Remember to flush the rules once manually after you added this code!
            // The regex to match the incoming URL
            // The resulting internal URL: <code>index.php</code> because we still use WordPress
            // <code>pagename</code> because we use this WordPress page
            // <code>designer_slug</code> because we assign the first captured regex part to this variable
            // This is a rather specific URL, so we add it to the top of the list
            // Otherwise, the "catch-all" rules at the bottom (for pages and attachments) will "win"
            'top' );
        //global $wp_rewrite;
    add_filter( 'query_vars', 'wpa5413_query_vars' );
    function wpa5413_query_vars( $query_vars )
        $query_vars[] = 'artist_slug';
        return $query_vars;

    Then, create a new page called "artist" with a template that will have the following simple code (to catch the rest of rthe url as a normal parameter):

    Template Name: ArtistPage
    global $wp_query;
    if(isset($wp_query->query_vars['artist_slug'])) {
        $test_slug = urldecode($wp_query->query_vars['artist_slug']);
    echo $artist_slug;

    Home it helps!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.