Skip to:
Content
Pages
Categories
Search
Top
Bottom

Another pretty permalink/mod_rewrite mystery

  • I have bbPress installed in a directory called “forums” on my web server. I have Pretty Permalinks enabled and working. To view the profile of a member, I can go to this URL:

    http://www.example.com/forums/profile/membername

    However, I would like the url to be:

    http://www.example.com/profile/membername

    I’ve tried writing a mod_rewrite rule which rewrites the latter to the former. However, instead of rewriting it, it redirect and exposes the URL. For example. Typing this into the browser:

    http://www.example.com/profile/membername

    Redirects to this, instead of rewriting it:

    http://www.example.com/forums/profile/membername

    Here is the mod_rewrite I am using:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    Options +FollowSymlinks
    RewriteRule ^profile/membername$ /forums/profile/membername [L]
    </IfModule>

    If I change the rule to rewrite the URL to a simple text file, it rewrites properly and masks the URL. For example, this works:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    Options +FollowSymlinks
    RewriteRule ^profile/membername$ /forums/textfile.txt[L]
    </IfModule>

    Another example, I wrote this rule, as a test, to rewrite a URL to the rewrite-rules.php file:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    Options +FollowSymlinks
    RewriteRule ^profile/membername$ /forums/bb-admin/rewrite-rules.php [L]
    </IfModule>

    I type in this url into my browser:

    http://www.example.com/profile/membername

    And it redirects to ths instead:

    http://test.doublebad.com/forums/

    If I replace all the text in the rewrite-rules.php file with “test text”, then the URL rewrites properly.

    So it seems that when you are rewriting and URL to a bbPress php file, it will always redirect instead of rewriting, which is quite annoying. I’m trying to trace in the bbPress functions and settings where this is occuring. But I’m having no luck.

    Any suggestions?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I did some digging, and although I have not found a solution. I believe the conflict with mod_rewrite and bbPress is that bbPress is using the header() function to send raw HTTP headers to the client. I notice that two files contain header() functions that send a “Location:” header to the browser:

    • bb-load.php

    • pluggable.php

    These seem to be forcing bbPress to redirect the URLs, even after a mod_rewrite rule executes.

    I’m a total php novice, so I’m not really sure how to fix this.

    It looks like the culprit is the wp_redirect function() which includes the header() function. This function appears in several bbPress files. I’m not exactly sure what the intent of them are.

    In the functions.php file, I commented out lines 2061 and 2062 in the bbPress functions.php file:

    if ( $check != $uri && $check != str_replace(urlencode($_original_id), $_original_id, $uri) ) {
    //wp_redirect( $permalink );
    //exit;
    }

    This seems to be helping with the problem. Not sure if it’s going to break something else though.

    It looks like it indeed breaks something. If you comment out wp_redirect in the functions.php, you will be able to use mod_rewrite to rewrite a URL to a bbPress page. However, this breaks authentication, and causes bbPress to think you are not logged in, even if you are. Not sure how to fix this.


    Sam Bauers
    Participant

    @sambauers

    I don’t think the path modification you are trying to enable is possible out of the box.

    You might like to try looking at bb_repermalink() where I believe that redirection you are seeing is being forced.

    Hi Sam, I was able to fix this without messing with bb_repermalink. Instead I used a plugin filter for get_user_profile_link(), get_topic_link(), and get_forum_link() functions.

    Here’s the thread:

    http://bbpress.org/forums/topic/how-to-shorten-a-profile-link?replies=5#post-16184

    http://bbpress.org/forums/topic/nicer-slug-url-rewrite-plugin-done

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

You must be logged in to reply to this topic.