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...
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
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} .+
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.