wordpress change to friendly URL with variable using htaccess

I have a wordpress site with a page template and 1 variable call uid (user id) , and I wanna change it to friendly url.

from

Read More
http://localhost/forum/edit-profile/?uid=1

to

http://localhost/forum/edit-profile/1

or

http://localhost/forum/edit-profile/uid/1

P/S: wordpress already has a .htaccess file , i just wanna add some additional codes to this.

I tried these solutions, but they are not working:

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

RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
</IfModule>

Related posts

Leave a Reply

1 comment

  1. Add this to your .htaccess rules

    RewrieCond %{QUERY_STRING} !no-redir [NC]
    RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
    RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d # not a dir
    RewriteCond %{REQUEST_FILENAME} !-f # not a file
    RewriteRule ^(.*/edit-profile)/(d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
    

    This would redirect /forum/edit-profile/?uid=1 to /forum/edit-profile/1 and back.

    EDIT : (with wordpress rules they should go like)

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /forumengine/
    
      RewriteRule ^index.php$ - [L]
    
      RewrieCond %{QUERY_STRING} !no-redir [NC]
      RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
      RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]
    
      RewriteCond %{REQUEST_FILENAME} !-d # not a dir
      RewriteCond %{REQUEST_FILENAME} !-f # not a file
      RewriteRule ^(.*/edit-profile)/(d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /forumengine/index.php [L]
    </IfModule>