Solved

Mod Rewrite Regex Syntax

Posted on 2008-10-12
1
138 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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