1

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

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

1 Answer 1

0

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} .+
Sign up to request clarification or add additional context in comments.

1 Comment

kidly give me whole code which i can replace to given code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.