Solved

using mod_rewrite

Posted on 2009-05-17
2
196 Views
Last Modified: 2012-05-07
I have a mod-rewrite rule that is _almost_ working,  I just need to know the conditional differences for it.

on the url:
http://example.com/go/campaign/subcampaign/purpose/url

the rule that will get me to the file i want is this one:
^go/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)(/.*)?$    script.php?mode=go&c=$1&s=$2&p=$3&u=$4 [QSA,L]

tested out here:
http://civilolydnad.se/projects/rewriterule/

and it produces:
Resulting URL: script.php?mode=go&c=campaign&s=subcampaign&p=purpose&u=url

which is exactly what i want.  Only problem is when not all of the url variables are set.  I need the script to work when there are less variables in the url too.

eg:
http://example.com/go/campaign/subcampaign/purpose
http://example.com/go/campaign/subcampaign/purpose/
http://example.com/go/campaign/subcampaign
http://example.com/go/campaign/subcampaign/
http://example.com/go/campaign
http://example.com/go/campaign/
http://example.com/go
http://example.com/go/

What would the rule be that covered all these options?
when there are less variables in the urls the destination can either omit or have no value for the destination url

Resulting URL: script.php?mode=go&c=campaign&s=&p=&u=
is ok and so is:
Resulting URL: script.php?mode=go&c=campaign

Thanks

0
Comment
Question by:ussher
2 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 500 total points
ID: 24405349
One solution is to use multiple rules.
RewriteRule ^go/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)(/.*)?$    script.php?mode=go&c=$1&s=$2&p=$3&u=$4 [QSA,L]

RewriteRule ^go/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    script.php?mode=go&c=$1&s=$2&p=$3 [QSA,L]

RewriteRule ^go/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    script.php?mode=go&c=$1&s=$2 [QSA,L]

RewriteRule ^go/([A-Za-z0-9-]+)/?$    script.php?mode=go&c=$1 [QSA,L]

Open in new window

0
 
LVL 1

Author Closing Comment

by:ussher
ID: 31582327
Yip, Nice one.  its simple and it works. Thanks.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now