my .htaccess file path is in cp folder. and i have alot file like home.php and cart.php. i need this for any url
To act on any URL-path then you could do something like the following near the top of the /cp/.htaccess
file using mod_rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*&)?(language=)(?!portuguese-pt(?:&|$))[^&]*(&.*)?$
RewriteRule ^ %{REQUEST_URI}?%1%2portuguese-pt%3 [NE,R=302,L]
The RewriteRule
pattern ^
is successful for any URL-path.
The preceding condition (RewriteCond
directive) matches the query string. It is only successful when the language
URL parameter exists, but not equal to portuguese-pt
(as determined by the negative-lookahead). The value of the language
URL param is otherwise discarded.
We capture the parts of the query string that surround the language
URL parameter value. These are saved in the following backreferences:
%1
/ pattern (.*&)?
- the part of the query string before the language
URL parameter (if any). This includes the &
delimiter before the language
URL param.
%2
/ pattern (language=)
- captures the literal text language=
. This must match to be successful. This simply saves repetition later.
%3
/ pattern (&.*)?
- the part of the query string after the language
URL parameter (if any). This includes the &
delimiter after the language
URL param.
The REQUEST_URI
server variable in the substitution string contains the full root-relative URL-path. We follow this with the query string that we rebuild using the backreferences as explained above, injecting portuguese-pt
as the value of the language
URL param (replacing any other value this URL parameter might have had).
The NE
(noescape
) flag is required to prevent the &
(URL param delimiter) being URL-encoded in the response.
Test first with a 302 (temporary) redirect to avoid potential caching issues, even if you change this to a permanent redirect later.