Title: Custom Permalink structure
Last modified: August 18, 2016

---

# Custom Permalink structure

 *  Resolved [foo bar](https://wordpress.org/support/users/nielshackius/)
 * (@nielshackius)
 * [20 years ago](https://wordpress.org/support/topic/custom-permalink-structure/)
 * Hello,
    what I would like to do is adding a rewrite-rule that redirects me to
   a certain wordpress-page and passes an additional variable, like this:
 * WORDPRESS/index.php/singapore/hello
 * –> index.php?page_id=67&gallery=hello
 * Thats what I do now:
    ` add_action('rewrite_rules_array',array($this,'singaporeRewriteRules'));`
 * function singaporeRewriteRules($rewrite)
    { global $wp_rewrite; // add rewrite
   tokens $keytag_token = '%gallery%'; $wp_rewrite->add_rewrite_tag($keytag_token,'(.
   +)', 'page_id='.get_option('singapore_page').'&gallery='); $keywords_structure
   = $wp_rewrite->root ."singapore/$keytag_token"; $keywords_rewrite = $wp_rewrite-
   >generate_rewrite_rules($keywords_structure); return ( $rewrite + $keywords_rewrite);}
 * This is what I get in the rewrite_rules_array:
 * [index.php/singapore/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?page_id
   =67&gallery=$matches[1]&feed=$matches[2]
 *  [index.php/singapore/(.+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?page_id=
   67&gallery=$matches[1]&feed=$matches[2]
 * [index.php/singapore/(.+)/page/?([0-9]{1,})/?$] => index.php?page_id=67&gallery
   =$matches[1]&paged=$matches[2]
 * [index.php/singapore/(.+)/?$] => index.php?page_id=67&gallery=$matches[1]
 * Well, nice, but it doesn’t work. What do I do?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [foo bar](https://wordpress.org/support/users/nielshackius/)
 * (@nielshackius)
 * [20 years ago](https://wordpress.org/support/topic/custom-permalink-structure/#post-400549)
 * No ideas? :-[
 *  [qrof](https://wordpress.org/support/users/qrof/)
 * (@qrof)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/custom-permalink-structure/#post-400655)
 * [This thread](https://wordpress.org/support/topic/62400?replies=7) might help
   out, it helped me. Especially the part about refreshing wp_rewrite option!
 *  [katesgasis](https://wordpress.org/support/users/katesgasis/)
 * (@katesgasis)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/custom-permalink-structure/#post-400656)
 * Are adding rewrite rules or concatenating? return($rewrite + $keywords_rewrite)
   looks funny. Shouldn’t it be return($rewrite . $keywords_rewrite) ?
 *  Thread Starter [foo bar](https://wordpress.org/support/users/nielshackius/)
 * (@nielshackius)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/custom-permalink-structure/#post-400659)
 * You do this because you combine two arrays, rather than two strings kategasis.
 * And thank you qrof..I will read this and if it helps I will post a solution.
 *  [sargant](https://wordpress.org/support/users/sargant/)
 * (@sargant)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/custom-permalink-structure/#post-400660)
 * I found that in order to receive extra variables over GET that I had specified
   in a rewrite, I had to specify them as “safe” query variables like so:
 * `add_filter('query_vars', 'add_my_safe_query_vars');`
 * function add_my_safe_query_vars($original_vars)
    { $extras = array('foo', 'bar');
   return array_merge($original_vars, $extras); }
 * You can then access them as `get_query_var('foo')` etc.
 *  Thread Starter [foo bar](https://wordpress.org/support/users/nielshackius/)
 * (@nielshackius)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/custom-permalink-structure/#post-400675)
 * Okay, the solution was more or less my own stupidity. You don’t get the variables
   like you might expect in $_POST, $_GET or $_REQUEST. You have to include them
   as a global.
 * For the example I started out with it would be
    ` function xyz() { global $gallery;
 *  //...
    }
 * And also sargant was completly right – don’t forget that!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Custom Permalink structure’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [mod_rewrite](https://wordpress.org/support/topic-tag/mod_rewrite/)
 * [rules](https://wordpress.org/support/topic-tag/rules/)

 * 6 replies
 * 4 participants
 * Last reply from: [foo bar](https://wordpress.org/support/users/nielshackius/)
 * Last activity: [19 years, 9 months ago](https://wordpress.org/support/topic/custom-permalink-structure/#post-400675)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
