Solved

Mod Rewrite Regex Syntax

Posted on 2008-10-12
1
141 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

626 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