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

---

# (Complex?) .htaccess problem

 *  Resolved [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 9 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 15 replies - 1 through 15 (of 20 total)

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

 *  [Christopher J. Hradil](https://wordpress.org/support/users/chradil/)
 * (@chradil)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-435887)
 * Are the rules for brands, ads, slogans requests for actual physical directories?
 * if not, your rules will need to be before the WP rules, not AFTER, since the 
   wp rules will intercept everything that’s not a physical directory or file, they
   may just work fine if placed at the top of the .htaccess file rather than after
   the WP rules.
 * second, you might try something like
    ` RewriteRule ^brands/(.*)/(.*) /brands/?
   b=$1&l=$2 ` to eliminate all of the iterations of different letter and number
   combinations.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-435891)
 * `# 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
 * This set of rules has a flaw. The first rule will never take effect, it’ll go
   to index.php every time.
 * Why? Because you failed to mark your new RewriteRule as Last, thus ending the
   processing.
 * Change:
    RewriteRule ^brands/([0-9]+) /brands/?b=$1 to: RewriteRule ^brands/([
   0-9]+) /brands/?b=$1 [L]
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-435955)
 * thanks for your answers, chradil and otto!
 * those rules are for accessing self-made template pages that take 2 variables:
   –
   b for brand ID – l for brand letter
 * what it should do is follow these links to the right destination:
 * 1- [http://localhost/brands/139/W/Wonka](http://localhost/brands/139/W/Wonka)-
   > Brand: Wonka
    2- [http://localhost/brands/W](http://localhost/brands/W) -> 
   All brands with letter W 3- [http://localhost/brands/Web](http://localhost/brands/Web)-
   > All brands in the web industry
 * in 1.5 i had these exact rules
    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
 * which worked.
 * now it doesn’t because it’s somehow 2.0.2 and the redirecting works differently.
 * looking forward to your answers guys
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436055)
 * Add [L] after each one of them, to force it to stop processing after that. Otherwise,
   the index.php will get loaded instead, because “.” matches everything.
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436068)
 * thanks otto but still doesn’t work.
 * excerpt:
    # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase/
 * RewriteRule ^brands/([0-9]+)/([A-Z]) /brands/?b=$1&l=$2 [L]
    RewriteRule ^brands/([
   A-Z])$ /brands/?l=$1 [L] RewriteRule ^brands/([a-z-A-Z]+) /brands/?in=$1 [L] 
   RewriteRule ^ads/([0-9]+)/([0-9]+) /ads/?ad=$1&b=$2 [L] RewriteRule ^ads/([A-
   Z])$ /ads/?l=$1 [L] RewriteRule ^ads/([0-9]+) /ads/?b=$1 [L] RewriteRule ^ads/([
   a-z-A-Z]+) /ads/?in=$1 [L] RewriteRule ^slogans/([A-Z])$ /slogans/?l=$1 [L] RewriteRule
   ^slogans/([a-z-A-Z]+) /slogans/?in=$1 [L]
 * RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
 * RewriteRule . /index.php [L]
 * </IfModule>
 * # END WordPress
 *  [vkaryl](https://wordpress.org/support/users/vkaryl/)
 * (@vkaryl)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436090)
 * All those “special” rules MUST be outside the # BEGIN WordPress line if I understand
   correctly; they cannot live within the wordpress conditional tags. That means
   you will no doubt need to do a begin Rewrite Engine On etc. beforehand.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436138)
 * No, they can be inside the WordPress comments. That bit doesn’t matter.
 * The only thing I can thing of is that you’re not matching your input URL with
   those rules. The rules look fine to me otherwise.
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436204)
 * I tried everything, outside, inside.
    The only thing that’s sure is
 * RewriteRule ^brands/([0-9]+) /brands/?b=$1
    works when i go to [http://localhost/brands/13](http://localhost/brands/13)
 * It seems wordpress index.php is chopping off the other parameter?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436234)
 * No, WordPress has nothing to do with this. Really.
 * If you get to index.php, then your RewriteRules _did not work_. All rewriting
   happens before a single line of PHP code gets executed. This has absolutely nothing
   to do with WordPress in particular, it’s a pure Apache/mod-rewrite question.
 * This line:
    `RewriteRule . /index.php [L]` is a catch-all. The “.” matches everything,
   so if index.php loads at all, then your RewriteRules above it did not match anything.
   See?
 * Saying it doesn’t work is useless unless you say *how* it doesn’t work.
    -What
   are the exact rules that you have in the .htaccess file? -What is the exact URL
   that does not work? -What do you expect that exact URL to get rewritten to?
 * Until you post these, nobody can help you. This is not a WordPress issue. Again,
   something is wrong with your RewriteRules. Period.
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436300)
 * First, thanks again for your willingness to help. Great!
 * – in 1.5 (still live at [http://www.brandinfection.com/brands/15/W/Wrigley](http://www.brandinfection.com/brands/15/W/Wrigley))
   these exact rewrite rules worked. I don’t know why they do not now
 * – I want to have an URL like [http://localhost/brands/139/W/Wonka](http://localhost/brands/139/W/Wonka)
   which would translate in [http://localhost/brands/?b=139&l=W](http://localhost/brands/?b=139&l=W)(
   where b is the brandID, l the letter “W”)
 * My rules in the .htaccess file so far:
 * # BEGIN WordPress
    <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /
 * RewriteRule ^brands/([0-9]+)/([A-Z])/?.* brands/?b=$1&l=$2 [L]
 * RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d RewriteRule./
   index.php [L]
 * </IfModule>
    # END WordPress
 * hope this helps you or others to understand my problem.
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436301)
 * i’ve set it up on my beta account so you guys can check it out.
 * [http://beta.brandinfection.com/brands/](http://beta.brandinfection.com/brands/)
 * click on any brand logo.
    error – 404 not found
 * it should be displaying the content at
 * [http://beta.brandinfection.com/brands/?b=39&l=N](http://beta.brandinfection.com/brands/?b=39&l=N)
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436302)
 * naderc: Okay, here’s a question. What script, exactly, are these supposed to 
   be redirecting to?
 * See, beta.brandinfection.com/brands/?b=39&l=N is in itself a rewritten thing.
   You’re not specifying a script there. Unless you add a redirect (which will change
   the URL that the user sees), then what’s going on is that you’re redirecting 
   to another directory, probably with it’s own .htaccess and RewriteRules. But 
   that won’t work, see, because the catch all in the WordPress directory has precedence(
   higher directory).
 * So what are you actually running here? What script is being run? Try specifying
   the WHOLE url and see if that works.
 * I can tell you right now that it will definitely work by changing the [L] into
   an [R,L], but that’s probably not the effect you’re wanting, since the pretty
   URLs will disappear from the user’s browser that way.
 * What is in the .htaccess of the brands directory?
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436303)
 * /brands is a wordpress page with page-name “brands”, so it’s not a real directory
 * Story behind:
    I wrote a plugin, that displays all various brands. I then created
   a page template called “brands” (brands.php) which i use as normal wordpress 
   page. With a couple of functions out of the plugin.
 * I tried to change [L] to [R] and you’re right, that works but is not the nice-
   url I want to have.
 * Hm, weird. What do you think?
 *  Thread Starter [Nader](https://wordpress.org/support/users/naderc/)
 * (@naderc)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436304)
 * RewriteRule ^brands/([0-9]+)/([A-Z])/?.* [http://beta.brandinfection.com/brands/?b=$1&l=$2](http://beta.brandinfection.com/brands/?b=$1&l=$2)[
   L]
 * This rule works for URLs like
    [http://beta.brandinfection.com/brands/139/W/Wonka](http://beta.brandinfection.com/brands/139/W/Wonka)
 * but at the end there’s written
    [http://beta.brandinfection.com/brands/?b=139&l=W](http://beta.brandinfection.com/brands/?b=139&l=W)
 * in the url bar.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 9 months ago](https://wordpress.org/support/topic/complex-htaccess-problem/#post-436306)
 * > /brands is a wordpress page with page-name “brands”, so it’s not a real directory
 * Oh. You didn’t say that earlier.
 * Well, there’s your problem. There’s no way to do what you want to do with WordPress
   2.0. The rewrites changed in a fairly fundamental way, and you don’t have the
   ability to do that sort of thing anymore.
 * Use R and live with the ugly URL, or write your plugin in such as way that it
   intercepts the URL before it hits WP-Rewrite and such.

Viewing 15 replies - 1 through 15 (of 20 total)

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

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, 9 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
