how to redirect sub folder query string url using htaccess

Good Evening….

i have my site in wordpress and i don’t want query string url to index in google search result, so for this i used below code for home page url like this

Read More
RewriteCond %{QUERY_STRING} .
RewriteRule ^$ /? [R=301,L]

RewriteCond %{THE_REQUEST} ?
RewriteCond %{QUERY_STRING} =""
RewriteRule .? %{REQUEST_URI}? [R=301,L]

by using the above code below url automatically redirect to home url…

http://example.com/? or http://example.com/?paramater=1

redirect on…

http://example.com

but my concern is that the above code is not working for sub folder or sub directories like..

http://example.com/folder/?paramater=1 or http://example.com/folder/?

should be redirect on..

http://example.com/folder/ or http://example.com/folder/ respectively…..

can anybody help me in order to correct above code..

thanks

Related posts

1 comment

  1. You can use the following code to remove query strings from urls :

    RewriteEngine on
    
    
    RewriteCond %{QUERY_STRING} .+
    RewriteRule ^ %{REQUEST_URI}? [L,R=301]
    

    The reason why your redirect is not working is because you are checking for empty query strings.

    RewriteCond %{QUERY_STRING} =""
    

    You need to check if the query string exists

    RewriteCond %{QUERY_STRING} .+
    

Comments are closed.