Solved

Mod Rewrite Regex Syntax

Posted on 2008-10-12
1
140 Views
Last Modified: 2010-03-04
Here's a sample of some code from my .htaccess file

RewriteRule ^TMP/Cat(.*)/(.*)$ /TMP/run.php?r=cat$1&c1=$2

How can I get this to return valid if the user types a url with ot without a trailing slash?
with my above example  /TMP/Cat1/2  works but  /TMP/Cat1/2/  does not
----------------------------------------------------------------------------------------------------

RewriteRule ^TMP/Cat(.*)/(.*)/(.*)/(.*)$ /TMP/run.php?r=cat$1&c1=$2&c2=$3&o=$4
RewriteRule ^TMP/Cat(.*)/(.*)/(.*)$ /TMP/run.php?r=cat$1&c1=$2&o=$3
RewriteRule ^TMP/Cat(.*)/(.*)$ /TMP/run.php?r=cat$1&c1=$2

Anyway to consolidate this?

I don't want to have to add filler to my URLS.

i.e.  I want the following urls to work with one entry in my htaccess file if that is possible: (keep in mind my first question)

/TMP/Cat1/2
/TMP/Cat1/2/3
/TMP/Cat1/2/3/4

I don't want to have to write a url like this:

/TMP/Cat1/2/0/0  then have my script ignore the zeros as a workaround




0
Comment
Question by:Bob-Villa
[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
1 Comment
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
ID: 22700949
You can make a / optional by adding a '?' --> /?
RewriteRule ^TMP/Cat([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /TMP/run.php?r=cat$1&c1=$2&c2=$3&o=$4 [L]
RewriteRule ^TMP/Cat([^/]+)/([^/]+)/([^/]+)/?$ /TMP/run.php?r=cat$1&c1=$2&o=$3 [L]
RewriteRule ^TMP/Cat([^/]+)/([^/]+)/?$ /TMP/run.php?r=cat$1&c1=$2 [L]

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

734 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