Apache.htaccess: how to remove a question mark from a URL, if not `? Id = (. *) `?

How to make .htaccess to remove a question mark from a URL if not ?id=(.*)

# Rewrite for ?id=(.*)
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule .*$ %{REQUEST_URI}%1? [R=301,L]

# It does not work out on this way
RewriteCond %{QUERY_STRING} !=""
RewriteCond %{QUERY_STRING} !^id=.*
RewriteRule .*$ %{REQUEST_URI}%1? [R=301,L]
+2
source share
3 answers

This will be the correct rule:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?#\ ]*)\?[^\ ]*\ HTTP/ [NC]
RewriteCond !{QUERY_STRING} id
RewriteRule .*$ %{REQUEST_URI}? [R=301,L]

Update

# Query rewrite exceptions
RewriteCond %{QUERY_STRING} !callback=.*
+1
source

It works?

RewriteCond %{QUERY_STRING} ^.+$
RewriteCond %{QUERY_STRING} !^id=
RewriteRule ^(.*)$ $1?%1 [R=301,L]

Tip. During testing, use 302 redirects instead of 301, since 301 redirects are stored in browsers. You can finally switch to classic 301 when you are done testing.

0
source

http://site.com/page/?YOURSTRING=blabla

http://site.com/page/

- fooobar.com/questions/10725/...

0

All Articles