RewriteRule ^escape-room-teambuilding-aktivitet/\?gclid=([^/]*)/?$ ?mobile=1&gclid=$1
The RewriteRule
pattern matches the URL-path only, which notably excludes the query string, so the above will never match.
([^/]*)
is also the wrong regex to use here since this is part of the query string, where parameters are delimited by &
, not /
(as in the URL-path).
You could probably just use the QSA
(Query String Append) flag to append the original query string from the request to the substitution string. This will include the gclid
parameter, but will also include any other URL parameters. For example:
RewriteRule ^example/$ index.php?mobile=1 [QSA,L]
Note the addition of index.php
in the substitution string. Your original directive is reliant on mod_dir. And the L
flag to prevent further processing.
This would rewrite a request of the form /example/?gclid=somevalue&foo=bar
to index.php?mobile=1&gclid=somevalue&foo=bar
.
Alternatively...
If, however, you wanted to target the gclid
URL parameter only (and discard all other URL parameters) then you would need a separate condition and check against the QUERY_STRING
URL parameter. For example:
RewriteCond %{QUERY_STRING} (?:^|&)(gclid=[^&]+)?
RewriteRule ^example/$ index.php?mobile=1&$1 [L]
This would replace your existing rule since it handles URLs both with and without the gclid
URL parameter.
This would rewrite a request of the form /example/?gclid=somevalue&foo=bar
to index.php?mobile=1&gclid=somevalue
. And /example/?foo=bar
to index.php?mobile=1&
(the trailing &
is inconsequential).
Aside:
RewriteRule ^some-words-words-here//?$ ?mobile=1
This doesn't match the stated example URL (so make sure you are editing the correct rule!). The trailing //?$
is also a bit odd. This is the same as simply /$
(a trailing slash is mandatory) because multiple contiguous slashes in the URL-path are reduced in the URL-path that is matched by the RewriteRule
pattern. You are also missing the L
flag, so the outcome is unpredictable if you have other directives that follow. (And, as mentioned above, you should be rewriting directly to index.php
, not relying on the DirectoryIndex
(mod_dir)).
gclid
is still present in the visible URL that Adwords sees. (?) Adwords does not see the rewritten URL that contains themobile
URL parameter (and nogclid
param) since this is entirely internal to your server. (?)