Solved

using mod_rewrite

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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