Title: (Complex?) .htaccess problem
Last modified: August 18, 2016

---

# (Complex?) .htaccess problem

 *  Resolved [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/)
 * To say it right at the beginning. I have searched the forums for hours, checked
   several mod_rewrite tutorials and still didn’t find an answer.
 * I just upgraded from 1.5 to 2.0.4 and so far every category, page, post works
   fine
 * BUT
 * my redirect rules for my brand, slogans and ad pages do not work anymore.
 * My rules were:
 * RewriteRule ^brands/([0-9]+)/([A-Z]) /brands/?b=$1&l=$2
    RewriteRule ^brands/([
   A-Z])$ /brands/?l=$1 RewriteRule ^brands/([a-z-A-Z]+) /brands/?in=$1 RewriteRule
   ^ads/([0-9]+)/([0-9]+) /ads/?ad=$1&b=$2 RewriteRule ^ads/([A-Z])$ /ads/?l=$1 
   RewriteRule ^ads/([0-9]+) /ads/?b=$1 RewriteRule ^ads/([a-z-A-Z]+) /ads/?in=$
   1 RewriteRule ^slogans/([A-Z])$ /slogans/?l=$1 RewriteRule ^slogans/([a-z-A-Z]
   +) /slogans/?in=$1
 * When I insert this after the wordpress rules in the 2.0.4 version, it doesn’t
   work.
 * Somehow WordPress always redirects it to index.php!?
 * One rule like the one below in combination with wordpress standard rules work
   well. The other things don’t anymore.
 * # BEGIN WordPress
    <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /
 * RewriteRule ^brands/([0-9]+) /brands/?b=$1
 * RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d RewriteRule./
   index.php [L] </IfModule> # END WordPress
 * It works on my 1.5 installation here: [http://www.brandinfection.com](http://www.brandinfection.com)
 * Please, please help me as this is the last problem till I can relaunch with the
   new version and cool features 🙂

Viewing 5 replies - 16 through 20 (of 20 total)

[←](https://wordpress.org/support/topic/complex-htaccess-problem/?output_format=md)
[1](https://wordpress.org/support/topic/complex-htaccess-problem/?output_format=md)
2

 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/#post-436307)
 * OMG, damn…I should have known earlier. Argh.
 * Do you know how to do this URL interception thing? At what points? in the template
   or just the plugin?
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/#post-436308)
 * I’d be even willing to buy you a small book at amazon.com or something :), if
   it would work out.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 10 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/#post-436309)
 * Basically, the old .htaccess method of doing rewrites was changed to be internal
   to wordpress. Now you can hook into the URL directly.
 * Info and examples are here. Skip down to where it says “Plugin Hooks”.
    [http://codex.wordpress.org/Function_Reference/WP_Rewrite](http://codex.wordpress.org/Function_Reference/WP_Rewrite)
 * Basically, you can probably dump those fake pages entirely, and just hook in 
   your plugin to notice the “brands” token in the URL and then do whatever you 
   please. They have an example on that page that add a “tag” token and converts
   the resulting URLs into “?tag=*”.
 * But basically, you create a new filter function. This will receive rewrite rules.
   You’ll generate your own set of rules using the add_rewrite_tag and generate_rewrite_rules
   functions, then append your rules onto the received rules, and return them. Then
   you add the filter to the rewrite_rules_array. It’s not too difficult, really.
 * You may need to rework your plugin so as to not make the keys so generic. b and
   l and such. Make them named, like brands and letter and so forth. Nobody will
   see the names anyway, after your rewriting.
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/#post-436310)
 * i have some kind of logic going on in the brands template page.
 * i don’t know at what part i should add a filter and how everything fits together.
   i’ve never done something with filters.
 * basically i have to add this function to the plugin and somewhere add filter?
   what do i do in the template page?
 * in my plugin i have functions like:
    one_brand($ID) all_brands($letter, $in, 
   $limit, $breakafter, $orderby)
 * Excerpt, brands.php template page:
 * `<?php
    // adaption for WP2: just isset doesn't work anymore, that's why we assign
   $_GET to $l, etc. $l = $_GET['l']; $b = $_GET['b']; $in = $_GET['in']; // adaption
   end
 *  if (! isset($b)) {
    if (! isset($l) && ! isset($in)) { $letter = ""; echo '<
   h2 class="capheadsmall" style="padding-top: 10px">RECENTLY ADDED BRANDS</h2>';
   all_brands($letter, $in, 21, 3, 'date'); } elseif (isset($l)) { $letter = $l;
   echo '<h2 class="capheadsmall" style="padding-top: 10px">BRANDS: ' . $letter .'
   </h2>'; all_brands($letter, $in, null, 3, 'brand_name'); } elseif (isset($in)){
   echo '<h2 class="capheadsmall" style="padding-top: 10px; text-transform: uppercase;"
   >' . str_replace("-", " ", $in) . ' Brands</h2>'; all_brands($letter, str_replace("-","",
   $in), null, 3, 'brand_name'); }
 *  } else {
    if (! isset($b)) { $ID = ""; } else { $ID = $b; } one_brand($b); all_ads(
   $ID, $in, $letter); brand_news($b); }
 * Excerpt plugin:
 * `
    function one_brand ($ID) { $letter = $_GET['l']; global $wpdb; $sql = "SELECT
   ID, brand_name, brand_desc, brand_industry, brand_link, brand_img FROM wp_brands
   WHERE ID = $ID AND brand_active = 1"; $results = $wpdb->get_results($sql); $output
   = ''; foreach ($results as $result) { $brand_name = stripslashes($result->brand_name);
   $brand_link = $result->brand_link; $brand_img = $result->brand_img; $brand_desc
   = stripslashes($result->brand_desc); $brand_industry = $result->brand_industry;
   $output .= '<div style="line-height: 17px; padding-top: 10px">' . $before;
 *  if ($brand_img != "") {
    $output .= '<div style="float: right; padding-left:
   20px; padding-bottom: 0px; padding-top: 10px"><img src="/wp-content/random-brand/'.
   $brand_img . '" style="margin: 3px 0 5px 0" alt="Link: ' . $brand_name . '" /
   ></div>'; }
 *  $output .= '<h2 style="padding-bottom: 0px; margin-bottom: 3px; color: #2e2e2e"
   >'. $brand_name . '</h2>Industry: ' . $brand_industry . '
   [ ' . $brand_link . '](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/&apos; . $brand_link . &apos;?output_format=md)
 * ' . $brand_desc . $after . '</div>';
    } echo $output;
 *  // Display Brandlinks
    $sql = "SELECT * FROM wp_brands_links WHERE brandID =
   $ID"; $results = $wpdb->get_results($sql); if ($results != "") { $output = '<
   div class="brands_links"><h4 style="margin-top: 0; padding-top: 3px">Pages found
   on ' . substr($brand_link, 7) . ' <span style="font-weight: normal">(beta)</span
   ></h4>'; $trenn = ""; foreach ($results as $result) { $type = $result->type; 
   $link = $result->link; if ($type == 4) { $output .= $trenn . '[About](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/&apos; . $link . &apos;?output_format=md)';
   $trenn = " | "; } if ($type == 1) { $output .= $trenn . '[News](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/&apos; . $link . &apos;?output_format=md)';
   $trenn = " | "; } if ($type == 6) { $output .= $trenn . '[Products](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/&apos; . $link . &apos;?output_format=md)';
   $trenn = " | "; } if ($type == 7) { $output .= $trenn . '[Shop](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/&apos; . $link . &apos;?output_format=md)';
   $trenn = " | "; } if ($type == 5) { $output .= $trenn . '[Jobs](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/&apos; . $link . &apos;?output_format=md)';
   $trenn = " | "; } if ($type == 2) { $output .= $trenn . '[Press](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/&apos; . $link . &apos;?output_format=md)';
   $trenn = " | "; } if ($type == 3) { $output .= $trenn . '[Contact](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/&apos; . $link . &apos;?output_format=md)';
   $trenn = " | "; } } echo $output . "</div>"; }
 *  // Display Slogans
    $sql = "SELECT * FROM wp_brands_slogans WHERE brandID = 
   $ID ORDER BY year DESC"; $results = $wpdb->get_results($sql); if ($results !=""){
   $output = '<h2 class="capheadsmall" style="margin-top: 30px; margin-bottom: 5px;
   text-transform: uppercase">' . $brand_name . ' Slogans</h2><table cellpadding
   ="0" cellspacing="0" width="100%">'; foreach ($results as $result) { $slogan_desc
   = stripslashes($result->desc); $slogan_year = $result->year; if($slogan_year 
   == "0000") { $slogan_year = ""; } $output .= '<tr><td width="90%" style="border-
   bottom: 1px solid #F3E9E2">' . $slogan_desc . '</td><td width="10%" style="padding:
   3px 0px 3px 0px; border-bottom: 1px solid #F3E9E2">' . $slogan_year . '</td></
   tr>'; } echo $output; echo "</table>"; } }
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 10 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/#post-436318)
 * > basically i have to add this function to the plugin and somewhere add filter?
 * Well, something like it anyway.
 * > what do i do in the template page?
 * You won’t have one any more. Move that functionality into the plugin.
 * Look man, I don’t know, all I do know is that the rewrite functions fundamentally
   changed. Don’t like it? Don’t upgrade then.

Viewing 5 replies - 16 through 20 (of 20 total)

[←](https://wordpress.org/support/topic/complex-htaccess-problem/?output_format=md)
[1](https://wordpress.org/support/topic/complex-htaccess-problem/?output_format=md)
2

The topic ‘(Complex?) .htaccess problem’ is closed to new replies.

## Tags

 * [htaccess](https://wordpress.org/support/topic-tag/htaccess/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)
 * [upgrading](https://wordpress.org/support/topic-tag/upgrading/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 20 replies
 * 4 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [19 years, 10 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/page/2/#post-436318)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
