?
Solved

using mod_rewrite

Posted on 2009-05-17
2
Medium Priority
?
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

777 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