skip to Main Content

We have been trying to create a dynamic redirect for the BuddyPress message Compose page using .htaccess rules. I would like for the Compose area to be inaccessible, but when someone clicks the "Private Message" button on someone’s profile, they can still get to the page and send a message to the user.

I found this post, but I can’t get my redirect to work – htaccess redirect exact match, exclude all query strings

The Compose area redirects to the home page fine, but when a query string is added during an attempt to message the user, we are redirected to the home page, but the query string remains in the URL.

Here is what I am using:

RewriteEngine On
RewriteBase /
RewriteRule ^members/([w-]+)/messages/compose/?$ / [L,R=302]

Any help on this would be appreciated.

Thank you.

2

Answers


  1. Chosen as BEST ANSWER

    This worked for me. Thanks everyone for your suggestions.

    # Redirect only when there is no query string present
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^members/([w-]+)/messages/compose/$ / [R=302,L]
    

  2. This should work for you. Remember to place the code at the top of your htaccess or before other directives .

    RewriteEngine on
    
    #Redirect the URL to / if no query string is present
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^members/([w-]+)/messages/compose/?$ / [L,R=302]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search