Forum Moderators: phranque
#Redirect to remove query string from any directory-paths
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteRule ^(.*)$ http://www.#*$!.com/$1? [R=301,L]
#Redirect to remove query string from any directory-paths
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteRule (.+) http://www.example.com/$1? [R=301,L]
([^&]+) is read until the next "&" and capture all before that. RewriteRule (.+) http://www.example.com/$1?gclid [R=301,L] does not work. This redirects all the www.example.com?page= urls to www.example.com?gclid etc. I do not want to redirect these urls, it is just that when an url contains '?gclid=' it does not get rewrited so that Google analytics can assess this as an Adwords url. RewriteRule (.+) http://www.example.com/$1?gclid [R=301,L] RewriteRule ^computer-repair/(.+)\.html$ /location.php?regio=$1 since this rule does not seems to work anymore... :s ([^&]+) is read until the next "&" and capture all before that.
Stop when you hit ampersand OR run out of stuff to process.
#Redirect to remove query string from any directory-paths
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L] %{QUERY_STRING} !gclid
But what happens to requests that would otherwise be rewritten? Don't you risk having identical requests being sent to different places depending purely on whether they contain the gclid element? Or is this something that could never occur anyway?
#Redirect to remove query string from any directory-paths
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L] %{QUERY_STRING} !gclid
something like this? cause it does not seems to work.
RewriteCond %{QUERY_STRING} !gclid And lucy, you saidBut what happens to requests that would otherwise be rewritten? Don't you risk having identical requests being sent to different places depending purely on whether they contain the gclid element? Or is this something that could never occur anyway?
gclid does only appear to an url if it is coming from adwords.. my site does not use 'gclid' at any place in any other url.. Does that settle your question?
#Redirect to remove query string from any directory-paths
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
RewriteCond %{QUERY_STRING} !gclid
RewriteRule ^computer-repair/(.+)\.html$ /region.php?region=$1
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
RewriteCond %{QUERY_STRING} !gclid
RewriteRule ^computer-repair/(.+)\.html$ /region.php?region=$1
Then the computer meets [L], meaning "stop here and go back to the very beginning of the htaccess file".
RewriteRule ^computer-repair/(.+)\.html$ /region.php?region=$1 i got from this website. Just by copy pasting it. The code above has been written by an scripter, who i can not contact. PHPsessionand urls like:
www.example.com/computer-repair/region1-region2-region3.html?page=computer-repair®ion=region1-region2-reion3since this is messing up my SEO (indexing in the search engines).
www.example.com?gclid=CMiA4avSzZkCFYZM5Qodaw3Muwalso need to be excluded from the rewrite conditions/rules.
RewriteCond %{QUERY_STRING} !^gclid RewriteRule ^computer-repair/(.+)\.html$ /region.php?region=$1
What i would like it to do is when it containts the "gclid" thing, i would like it to get rewrited like any other urls
RewriteRule ^computer-repair/(.+)\.html$ /region.php?region=$1This will make the ursl like:
example.com/computer-repair/region1-region2-region3.html
example.com/computer-repair/region1-region2-region3.html?gclid=blabla
www.example.com/computer-repair/region1-region2-region3.html?page=computer-repair®ion=region1-region2-region3. Something goes wrong there. So i would like to exclude this
?page=computer-repair®ion=region1-region2-region3thing from the urls so they get indexed the right way in google:
example.com/computer-repair/region1-region2-region3.html
All my urls get rewrited to SEO friendly urls
This will make the URLs like:
# Capture glcid parameter and remove all preceding (and following)
# parameters when glcid is present in middle or at end of parameters.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteCond %{QUERY_STRING} &glcid=([^&]+)
RewriteRule (.*) http://www.example.com/$1?glcid=%1 [R=301,L] # Capture glcid parameter and remove all following parameters
# when glcid is present as first parameter of multiple parameters.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteCond %{QUERY_STRING} ^glcid=([^&]+)&
RewriteRule (.*) http://www.example.com/$1?glcid=%1 [R=301,L] # Remove all parameters except when glcid is present.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteCond %{QUERY_STRING} !glcid=
RewriteRule (.*) http://www.example.com/$1? [R=301,L] # Canonical redirect.
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1? [R=301,L] [edited by: engine at 1:59 pm (utc) on Aug 2, 2011]
[edit reason] fixed typo [/edit]
# Capture glcid parameter and remove all preceding and following
# parameters when glcid is present in query string with multiple parameters.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteCond %{QUERY_STRING} !^glcid=[^&]+$
RewriteCond %{QUERY_STRING} glcid=([^&]+)
RewriteRule (.*) http://www.example.com/$1?glcid=%1 [R=301,L] # Remove all parameters except when glcid is present.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?#\ ]*)\?[^\ ]*\ HTTP/
RewriteCond $1 !^stats/
RewriteCond %{QUERY_STRING} !glcid=
RewriteRule (.*) http://www.example.com/$1? [R=301,L] # Canonical redirect.
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1? [R=301,L] [edited by: engine at 2:00 pm (utc) on Aug 2, 2011]
[edit reason] fixed typo [/edit]
!^glcid=[^&]+$ (meaning "not exactly") and glcid=([^&]+) (meaning "contains") are crucial to correct operation of the first ruleset, as is !glcid= (meaning "does not contain") in the following ruleset.