WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] .htaccess mod_rewrite help (10 posts)

  1. gh3
    Member
    Posted 7 years ago #

    Hi, i got a trouble.

    I use WP 2.0.4, actually my .htacess is the one generated as default by Wp

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    I wanted to add a new rule like:

    if i point on http://domain/profile/username.htm the system will turn in to
    http://domain/index.php?user=username

    I've write this rule:

    RewriteRule ^/profie/(.*).htm$ index.php?user=$1 [L]

    So my new .htaccess looked like this:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^/profie/(.*).htm$ index.php?user=$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    But if i browse http://domain/profile/username.htm, i always reach a 404 page made by WP.

    Any idea or suggestion to fix this?

    Thanks in advance.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    You misspelled "profile" in your rule. Also you should escape the dot.

    RewriteRule ^/profile/(.*)\.htm$ index.php?user=$1 [L]

  3. gh3
    Member
    Posted 7 years ago #

    i've fixed the mispelled and dot but it still redirect me to the 404 error of the theme

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Hmmm.. Change the [L] to [R,L] and see if that works.

  5. gh3
    Member
    Posted 7 years ago #

    no, it seems to love 404 page :(

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    gh3: Does the actual index.php?user=whatever page work if you use it directly?

  7. gh3
    Member
    Posted 7 years ago #

  8. gh3
    Member
    Posted 7 years ago #

    there's no way to get it work, but the wp rule works and anti hotlink of images works too :(

  9. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Well, I gotta say that I don't know what you're doing wrong, but that rule above is correct and will work. So I'd look at something else. Maybe your server config is bad. Dunno.

  10. gh3
    Member
    Posted 7 years ago #

    solved :)

    you have to add in functions.php of the theme a rule like:

    function foo_bar_rewrite_rules($rules) {
    global $wp_rewrite;
    $newrules['cerca.htm$'] = 'index.php?cerca';
    $newrules['profilo/(.+).htm$'] = 'index.php?user=$matches[1]';
    return array_merge($newrules,$rules);
    }
    add_filter('rewrite_rules_array','foo_bar_rewrite_rules');

    update_option('rewrite_rules', '');

    :D

Topic Closed

This topic has been closed to new replies.

About this Topic