Reputation: 1777
I want to remove question mark from the url and redirect to the same page without question mark.
My URL like:
http://domain.com/what-is-your-name?/21.php
URL needed:
http://domain.com/what-is-your-name/21.php
Upvotes: 1
Views: 3829
Reputation: 16923
This will remove any ?
mark from URL
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*)$ $1%1? [R,L]
put it on as your first rule in .htaccess
Short explanation:
RewriteCond %{QUERY_STRING} ^(.+)$
checks is there any GET query string (like ?foobar
or ?foo=bar
or ?/21.php
) in url, it also fill up the %1
variable.
When RewriteCond requirement if fullfiled, RewriteRule ^(.*)$
rewrites ANY url. $1
is filled with URL part before ?
mark. [R]
flag indicates it's a redirect. [L]
means it's a last rule.
I strongly recommend to not do this, and do it properly by fixing your links.
You can either escape question marks in URL's or remove it completely.
Upvotes: 5