Home > Back-end >  How To Rewrite Wordpress URL to remove ? parameter
How To Rewrite Wordpress URL to remove ? parameter

Time:10-20

I have the following URL in a wordpress website:

https://www.example.com/previews/mundoflamenco/gitarre/?gname=myname 

I would like it to be rewritten like so (so the ?gname= should be hidden):

https://www.example.com/previews/mundoflamenco/gitarre/myname 

I have tried it using .htaccess like so but it unfortunately doesn't work:

RewriteCond %{THE_REQUEST} /gitarre\?gname=([^\s&] ) [NC]
RewriteRule ^ gitarre/%1? [R=302,L]

Some more information:

just if anyone faces the same issue as I had after I managed to get the redirect working: Wordpress didn't find the page anymore after this (404):

You need to add the following in htaccess to tell wordpress to exclude this folder:

# BEGIN WordPress

RewriteRule ^index\.php$ - [L]
# add the following after this line

RewriteCond %{REQUEST_URI} !^/(gitarre|gitarre/.*)$ 

# END WordPress

CodePudding user response:

You may use this redirect rule just below RewriteEngine On line:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s(.*/gitarre/?)\?gname=([^\s&] ) [NC]
RewriteRule ^ %1/%2? [R=302,L,NE]

# remaining rules below this line
  • Related