• Resolved Nader

    (@naderc)


    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: https://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)
  • 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)

    (@otto42)

    www.ads-software.com Admin

    # 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

    (@naderc)

    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- https://localhost/brands/139/W/Wonka -> Brand: Wonka
    2- https://localhost/brands/W -> All brands with letter W
    3- https://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)

    (@otto42)

    www.ads-software.com Admin

    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

    (@naderc)

    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

    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)

    (@otto42)

    www.ads-software.com Admin

    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

    (@naderc)

    I tried everything, outside, inside.
    The only thing that’s sure is

    RewriteRule ^brands/([0-9]+) /brands/?b=$1
    works when i go to https://localhost/brands/13

    It seems wordpress index.php is chopping off the other parameter?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    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

    (@naderc)

    First, thanks again for your willingness to help. Great!

    – in 1.5 (still live at https://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 https://localhost/brands/139/W/Wonka which would translate in https://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

    (@naderc)

    i’ve set it up on my beta account so you guys can check it out.

    https://beta.brandinfection.com/brands/

    click on any brand logo.
    error – 404 not found

    it should be displaying the content at

    https://beta.brandinfection.com/brands/?b=39&l=N

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    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

    (@naderc)

    /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

    (@naderc)

    RewriteRule ^brands/([0-9]+)/([A-Z])/?.* https://beta.brandinfection.com/brands/?b=$1&l=$2 [L]

    This rule works for URLs like
    https://beta.brandinfection.com/brands/139/W/Wonka

    but at the end there’s written
    https://beta.brandinfection.com/brands/?b=139&l=W

    in the url bar.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    /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)
  • The topic ‘(Complex?) .htaccess problem’ is closed to new replies.