Solved

using mod_rewrite

Posted on 2009-05-17
2
201 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 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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