473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to remove string from URL using mod_rewrite

Coldfire
289 100+
I have this URL

http://www.mysite.com/customer/city/...k12j1b32l12lj3

I want to redirect the user to

http://www.mysite.com/customer/city/2

basically I need to remove this "?gclid=1kn23k12j1b32l12lj3" part

I need the RewriteCond and RewriteRule for it...
Jun 1 '10 #1
4 4277
Dormilich
8,658 Expert Mod 8TB
I’d try something like
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ([^?]+)\?.+ $1
Jun 2 '10 #2
Coldfire
289 100+
The above rule is not working for me.

Here is the htaccess that I have,

Expand|Select|Wrap|Line Numbers
  1. # Customized error messages.
  2. ErrorDocument 404 /index.php
  3.  
  4. # Set the default handler.
  5. DirectoryIndex index.php
  6.  
  7. # Various rewrite rules.
  8. <IfModule mod_rewrite.c>
  9.   RewriteEngine on
  10.   RewriteCond %{REQUEST_FILENAME} !-f
  11.   RewriteCond %{REQUEST_FILENAME} !-d
  12.   RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
  13.  
  14.   RewriteRule ([^?]+)\?.+ $1
  15.   #RewriteRule ^(.*)/(.*)/1?gclid=(.*)$  customer/city/1/ [L,QSA]
  16.   #RewriteRule ^(.*)/(.*)/2?gclid=(.*)$  customer/city/2/ [L,QSA]
  17.  
  18. </IfModule>
  19.  
This Rule works OK if I have only one destination page for the redirect. But, I have to redirect based on the query string e.g.

http://mysite.com/customer/city/2?gclid=adk131kh231k23h

then I will be redirected to

http://mysite.com/

Even If the url is

http://mysite.com/customer/city/1?gclid=K12K3HKH123K
i will be redirected to

http://mysite.com/

The RewriteRules I need are for following URL scenarious,


If City = 1

http://www.mysite.com/customer/city/...k12j1b32l12lj3
I want to be redirected to city 1 i.e.
http://www.mysite.com/customer/city/1



If City = 2

http://www.mysite.com/customer/city/...k12j1b32l12lj3
I want to be redirected to city 2 i.e.
http://www.mysite.com/customer/city/2


I have written the rules for them, but they doesnt seem to work correctly as they redirect me alwyas to http://mysite.com

Here are these,

Expand|Select|Wrap|Line Numbers
  1. #RewriteRule ^(.*)/(.*)/1?gclid=(.*)$  customer/city/1/ [L,QSA]
  2.   #RewriteRule ^(.*)/(.*)/2?gclid=(.*)$  customer/city/2/ [L,QSA]

Any help would be appreciated.

-
Jun 3 '10 #3
Dormilich
8,658 Expert Mod 8TB
from the RegEx point-of-view it works, but I can’t test it myself. even ^([^?]+)\?.+$ works. not sure if you have to add further flags.
Jun 4 '10 #4
iohos
45
ditto dormilich
Jul 25 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

44
by: Neil Cerutti | last post by:
In Rob Pike's style guide he urges the following: Simple rule: include files should never include include files. If instead they state (in comments or implicitly) what files they need...
4
by: darrel | last post by:
I'm trying to get a page up using some sample code that interfaces with a 3rd party application using .net. The sample code the company provides, when I run it, produces this error: ...
5
by: Lupus | last post by:
Hello everybody In apache I used a feature called a "Rewrite rule" inside a .htaccess file to process the URL : i.e. http://www/mypage.html =http://www/page.php?page=mypage Now I'd like to do...
1
by: soniamuk | last post by:
i am facing a typical issue with apache where i have a filter context(written in c++) which pulls information from apache server. in this process when i am trying to fetch an url where rewrite rule...
4
by: adamjblakey | last post by:
What would be the correct MOD Rewrite rule for this: http://www.website.co.uk/building-an...ices/cheshire/ I thought it would be: Code: RewriteRule ^building-and-construction/(+)/(+)/$...
0
by: andrewteg | last post by:
I have an application that is installed as http://domain.com/folder/ and serves pages as http://domain.com/folder/index.ext/parent/child/ and I'm trying to remove index.ext from the URL so that...
1
by: neovantage | last post by:
Can some one translate this Rewrite Rule RewriteRule ^(.*)/?$ index.php?mod=$1
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.