Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

using mod_rewrite

Posted on 2009-05-17
2
Medium Priority
?
204 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 43

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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…
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 …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

618 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