简体   繁体   中英

mod_rewrite rule: if URL contains a certain string to orginal

My client keeps editing the structure of the navigation in the website, which is leading to some mod_rewrite issues. How could i make this rule in apache:

the actual ur is

/AuthCont?FORMSGROUP_ID__=AuthenticationFG&__START_TRAN_FLAG__=Y&FG_BUTTONS__=LOAD&ACTION.LOAD=Y&AuthenticationFG.LOGIN_FLAG=1&T_ID=ND

but if user manually changes AuthenticationFG.LOGIN_FLAG=1 to AuthenticationFG.LOGIN_FLAG=2 or AuthenticationFG.LOGIN_FLAG=3 it should rewrite to actual AuthenticationFG.LOGIN_FLAG=1 kindly help

From: https://wiki.apache.org/httpd/RewriteQueryString

Modifying the Query String: Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.

RewriteCond %{QUERY_STRING} ^(.*)val(.*)$
RewriteRule /path /path?%1other_val%2

So you could try for example:

 RewriteCond %{QUERY_STRING} ^(.*)LOGIN_FLAG=2(.*)$
 RewriteCond %{QUERY_STRING} ^(.*)LOGIN_FLAG=3(.*)$
 RewriteCond %{QUERY_STRING} ^(.*)LOGIN_FLAG=4(.*)$
 # and so on for all the numbers...
 # then:
 RewriteRule /AuthCont /AuthCont?%1LOGIN_FLAG=1%2

EDIT

hrmm okay try this:

 RewriteCond %{QUERY_STRING} ^(.*)LOGIN_FLAG=(.*)$
 RewriteRule ^(.*)$ http://your_domain_here.com/AuthCont?FORMSGROUP_ID__=AuthenticationFG&__START_TRAN_FLAG__=Y&FG_BUTTONS__=LOAD&ACTION.LOAD=Y&AuthenticationFG.LOGIN_FLAG=1&T_ID=ND? [L]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM