Hi,
my URL looks like
page.html?L=0&a=1&b=2&c=6 OR page.html?a=1&b=2&L=0&c=6 OR page.html?a=1&b=2&c=6&L=0 I need to delete the L=0, where L can be either 0 or 1. But I need to keep all other params. How can this be done?
Hi,
my URL looks like
page.html?L=0&a=1&b=2&c=6 OR page.html?a=1&b=2&L=0&c=6 OR page.html?a=1&b=2&c=6&L=0 I need to delete the L=0, where L can be either 0 or 1. But I need to keep all other params. How can this be done?
Try this rule:
RewriteCond %{QUERY_STRING} ^(([^&]*&+)*)L=[01](&+(.*))?$
RewriteRule ^page\.html$ %{REQUEST_URI}?%1%4 [L,R=301]
Ok, I played around a lot on http://gskinner.com/RegExr/.
I simply can't find a regex that works on all these cases:
domain.com/login.html?p1=1&p2=2&L=0&P3=3 domain.com/login.html?p1=1&p2=2&L=1&P3=3 domain.com/login.html?p1=1&p2=2&L=0 domain.com/login.html?&L=0 domain.com/login.html?L=0 domain.com/login.html?L=0&p1=1&p2=2&P3=3
Last best guess was (.)(L=[a-zA-Z0-9]&?)(&?)(.) >>> $1$3$4
This resulted in
domain.com/login.html?p1=1&p2=2&P3=3 domain.com/login.html?p1=1&p2=2&P3=3 domain.com/login.html?p1=1&p2=2& domain.com/login.html?& domain.com/login.html? domain.com/login.html?p1=1&p2=2&P3=3
What I try is: - Cut out the L param if it is in the middle - Cut off the L param if it is at the end of a loner param string - Cut off the L param AND "?" if it is the only param
Can you provide some more hints?
Ok, another headache and I am finally there. I just post this here in case I
# Rewrite Typo3 links with multilanguage Param "L"
RewriteCond %{QUERY_STRING} (.*)(^L=[a-zA-Z0-9]+&?|^&L=[a-zA-Z0-9]+&|&L=[a-zA-Z0-9]+)(&?.*)
RewriteRule (.*) %{REQUEST_URI}?%1%3 [L,R=301]
The rule tries to cover all the following cases
As far as my knowledge goes, the regex works as follow:
Therefor the replacement only needs %{REQUEST_URI}?%1%3
. This will cut out the second ( ) group with the different L-param options.
The URL query string will be stripped of the L-param, but leave everything else.
Any comments? Feel free to vote if this is valuable for you, too.
Thanks to all who helped me find the correct solution!