I’m creating som custom templates in WordPress and I’m passing some data in the URL’s.

Currently my URL looks like this:
http://www.mysite.com/designers/?id=43&name=designer+name

The URL contains designer ID and designer name.

I would really like to use this:
http://www.mysite.com/designers/designer+name/

My permalink structure is set to /%category%/%postname%/

My .htaccess file looks like this:

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

I’ve looked at http://codex.wordpress.org/Using_Permalinks, but not become any wiser.

I got two questions:

  1. Is there any point in changing the above URL regarding SEO
  2. How can I get the “pretty” URL?

UPDATE
I’m adding some more info for clarification.

  • I’m developing the site myself
  • The template is 100% custom template
  • Based on info from $_GET, I load data from my custom DB table and display this on page
  • My site has an avarage of between 3-400 unique visitors per day. At peak I have 2000 unique visitors per day.
  • I’m developing an online fashion magazine
  • My URL is currently being created like this:

    Url = get_permalink().'?bid='.$brand->id.'&name=".$brand->name;

  • I”ve used similar method here:
    http://storelocator.no/search/?brandID=4673&storeID=0&brand=Moods+of+Norway

Using Custom Post Type was an option I considered, but I needed my own table structurem because designers / brands are linked up against galleries (and more links to other tables to come). So saving brands data in WP POST table was not going to work.

So I need to know this:

  • What do I need to do with my Permalink structure?
  • What do I need to do with my .htaccess file?

3 s
3

I don’t know (or didn’t know) much about the rewrite rules myself (but it seems nobody does), but based on some other answers here, I got this to work. We add a new rewrite rule that matches designers/designer_name/. We “flush” the rewrite rules so they get saved to the database, but make sure to do this only once, since it is an expensive operation. Now, we set up a pattern that will match our page and save the extra part in the designer_name query variable. Since WordPress does not know it must look at this variable, we hook into the query_vars filter and tell it to look at that too.

Now, in the page-designers.php theme file, we can do get_query_var('designer_name') and it will give you the designer name. If you want extra stuff like paging (designer/designer_name/page/2), you need to add an extra rewrite rule for that (or feeds, or whatever that starts with designer/designer_name). But the basic stuff should work.

<?php
/*
Plugin Name: WPA 3537
Plugin URI: http://wordpress.stackexchange.com/questions/3537/need-help-with-friendly-urls-in-wordpress
Description: Need help with friendly URL's in WordPress
Version: 1.0
Author: Jan Fabry
*/

register_activation_hook(__FILE__, 'wpa3537_flush_rules');
function wpa3537_flush_rules()
{
    add_rewrite_rule('designers/([^/]+)', 'index.php?pagename=designers&designer_name=$matches[1]', 'top');
    flush_rewrite_rules(false);
}

add_filter('query_vars', 'wpa3537_query_vars');
function wpa3537_query_vars($query_vars)
{
    $query_vars[] = 'designer_name';
    return $query_vars;
}

Leave a Reply

Your email address will not be published. Required fields are marked *