skip to Main Content

I have a WordPress site running in an apache server, I want to rewrite some the URL in SEO friendly manner, so how to do that

Currently, I have this URL

www.example.com/about-us/?id=what_we_do_1
www.example.com/about-us/?id=why_us

I want it like

www.example.com/about-us/what-we-do-1
www.example.com/about-us/why-us

and for this

www.example.com/media/?id=team
www.example.com/media/?id=abc_xyz

I want something like this

www.example.com/media/team
www.example.com/media/abc-xyz

my current .htaccess is like the below

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

2

Answers


  1. To convert urls like

    /index.php?p=test

    to

    /index.php/test

    RewriteEngine On
    RewriteCond %{QUERY_STRING} p=(.+)
    RewriteRule ^/?index.php$ /index.php/%1? [R,L]
    

    Thus in your case

    RewriteEngine On
    RewriteCond %{QUERY_STRING} p=(.+)
    RewriteRule ^/?about-us?$ /about-us/%1? [R,L]
    

    Similarly for other pages

    Login or Signup to reply.
  2. You can try these to convert underscore to dash :-

    RewriteEngine On
    RewriteBase /
    

    After that for another url :-

    1) http://www.example.com/about-us/?id=what_we_do_1

    htaccess rule will be :-

    RewriteRule ^about-us/(.*)$ about-us/?id=$1 [QSA,L]
    

    It may help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search