Replace character in query string with .htaccess

My client wants the query string to be distorted (by changing% to A) on certain pages.

For example, I can completely delete the query string on the desired pages with:

RewriteCond %{QUERY_STRING} !="" 
RewriteCond %{REQUEST_URI} ^/SpecialPage(.*) 
RewriteRule ^(.*)$ /$1? [R=301,L] #remove query string

Here, what I thought should remove% in the query string and replace with A, but it is not:

RewriteCond %{QUERY_STRING} ^(.*)\%(.*)$
RewriteCond %{REQUEST_URI} ^/SpecialPage(.*)
RewriteRule ^(.*)$ /$1?%1A%2  [L]

How am I wrong about this? I just can't notice it. Thanks for the expert’s eyes!

+5
source share
2 answers

You are really close.

The problem is that you have a condition, and the coincidence of your rule should be together. Your feedback from the previous one is RewriteCondbroken because it is for REQUEST_URI and not QUERY_STRING as you want.

RewriteCond %{REQUEST_URI} ^/SpecialPage(.*)
RewriteRule ^(.*)$ /$1?%1A%2  [L]

% 1 (.*) URI /SpecialPage. , , . REQUEST_URI RewriteRule:

RewriteCond %{QUERY_STRING} ^(.*)\%(.*)$
RewriteRule ^SpecialPage(.*)$ /SpecialPage$1?%1A%2  [L]

% 1 % 2 , SpecialPage URI .

+1


      RewriteEngine On
      RewriteCond% {QUERY_STRING} ^ (.) = (.) $
      RewriteRule ^ (.)? (.) $/$1 -% 0? [R = 301, L],

URL: http://localhost/sholay-slide.jsp?slide=2
URL: http://localhost/sholay-slide.jsp--slide=2

0

All Articles