• Hi,
    I’m using a rewriterule for my website:

    RewriteCond %{THE_REQUEST} pagename=immagini&gallerytag=([^\s\?]+)\s [NC]
    RewriteRule ^ immagini/ngg_tag/tags/%1? [R=301,L]
    # Internaly rewrite
    RewriteRule ^immagini/tags/(.*)/?$ /pagename=immagini&gallerytag=$1 [QSA,NC,L]

    Works fine, but when I’ll put the mouse cursor on the link, I see a not rewrited url, ex:
    https://www.site.com/?pagename=immagini&gallerytag=shoes
    Exist a way to mask a non friendly url also in html code? I not want see the posted parameters in url.

    Thanks
    Angelo

Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter anjx

    (@anjx)

    Sure, immagini is a real page created with wordpress.
    I’m using tags generated with Nextgen Gallery plugin.

    In your HTML, did you manually write those URLs like that?

    <ul>
    <li><a href="https://www.site.com/index.php?pagename=immagini&gallerytag=schoes">Shoes</a></li>
    <li><a href="https://www.site.com/index.php?pagename=immagini&gallerytag=clothes">Clothes</a></li>
    <li><a href="https://www.site.com/index.php?pagename=immagini&gallerytag=beauty">Beauty</a></li>
    </ul>

    If so, can you just replace them with the following:

    <ul>
    <li><a href="https://www.site.com/immagini/schoes">Shoes</a></li>
    <li><a href="https://www.site.com//immagini/clothes">Clothes</a></li>
    <li><a href="https://www.site.com/immagini/beauty">Beauty</a></li>
    </ul>

    That way, you will get the exact URL you’re looking for.

    Now, in order to translate one of the URLs, I’d add the gallerytag query var to WordPress:

    add_rewrite_tag('%gallerytag%', '([^&]+)');

    Then I would add the rewrite rule:

    add_rewrite_rule(
    	'^immagini/([-a-z]+)/?$',
    	'index.php?pagename=immagini&gallerytag=$matches[1]',
    	'top'
    );

    After that, create a custom page template for the immagini page by putting a file in your themes folder called page-immagini.php (or use the ID if the name may change) with the following contents:

    <?php
    
    global $wp_query;
    echo '<pre>' . print_r($wp_query, true) . '</pre>';

    Now, after you flush the permalinks and you visit example.org/immagini/ you’ll see $wp_query printed out.

    If you visit example.org/immagini/test, you’ll see that there will be a new element in the array like this:

    [gallerytag] => test

    With this, you can then query for the pictures with that tag.

    If you want to automatically display a list of all the tags in your immagini page, you can use something like this:

    global $post;
    
    $gallerytags = get_terms('ngg_tag');
    
    echo '<ul>';
    
    foreach ($gallerytags as $tag) {
    	echo '<li><a href="' . get_permalink($post->ID) . $tag->slug . '">' . $tag->name . '</a></li>';
    }
    
    echo '</ul>';

    Let me know if this answers your questions.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Rewriterule and mask original link from html’ is closed to new replies.