Add a trailing slash on a mod_rewrite rule

Hello,
I'm very new with mod_rewrite and I'm trying to get my own rules...
I have this simple line:

RewriteRule  ^concorso/(.*)/$    concorso/?iModule=13&iData=$1   [L]

Open in new window

It is working with URLs like:
http://www.mysite.com/concorso/2/
But not with URLs like
http://www.mysite.com/concorso/2
(no trailing slash)

I know that maybe this is a very common issue, but all the examples I find online are.. "oversized" for this simple rule

So, how can I automatically add a trailing slash? Please notice that a rule like:
RewriteRule    ^contatti/$    contatti/?iModule=10    [L]

Open in new window

adds automatically a slash...

Thanks for your help!
ivanhalenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaufmed   ( ⚆ _ ⚆ )I asked the operating system what I could do to become a better programmer. It said, "Let me give you some pointers."Commented:
Make the slash optional by adding a question mark to your rule:
RewriteRule  ^concorso/(.*)/?$    concorso/?iModule=13&iData=$1   [L]

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kaufmed   ( ⚆ _ ⚆ )I asked the operating system what I could do to become a better programmer. It said, "Let me give you some pointers."Commented:
Explanation:

Your original rule says to find the string "concorso", followed by any other string ( .* ), followed by a slash. Since the second example doesn't have this required slash, the rule doesn't match and is not applied. If you make the slash optional, as I mentioned above, then the rule should find either case, and hence apply its replacement pattern.
ivanhalenAuthor Commented:
Hi kaufmed, and thanks for the answer

Uhm... this doesn't work, I get this error in Apache log:
[Wed Dec 29 10:02:41 2010] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

and this in the Access log:
127.0.0.1 - - [29/Dec/2010:10:02:41 +0100] "GET /concorso/2/ HTTP/1.1" 500 535
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

ivanhalenAuthor Commented:
Ok, I only have to change this:

concorso/?iModule=13&iData=$1

with this

concorso/index.php?iModule=13&iData=$1

Don't know exactly why, but it works :-)
ivanhalenAuthor Commented:
Sorry, I talked too fast... with the last solution the page doesn't get an error but it's like the record is not there :-(
ivanhalenAuthor Commented:
At last this is the final solution taht works:

RewriteRule  ^concorso/([0-9]+)/?$    concorso/?iModule=13&iData=$1   [L]

Open in new window

kaufmed   ( ⚆ _ ⚆ )I asked the operating system what I could do to become a better programmer. It said, "Let me give you some pointers."Commented:
Here's an explanation of what happens:
RewriteRule                    -  This tells mod_rewrite this
                                  is intended to rewrite
                                  incoming URLS

^concorso/([0-9]+)/?$          -  This is the pattern to match
                                  the URL against

   ^            Beginning of incoming request string
   concorsor/   Literal text to match
   ( ... )      Capturing parentheses (referenced below)
   [0-9]+       any digit ( [0-9] ), one-or-more times ( + )
   /?           Zero-or-one ( ? ) of a literal slash
   $            End of incoming request string


concorso/?iModule=13&iData=$1  -  This is what you will replace
                                  the incoming request string with

   Everything in the replacement is literal with the exception
   of "$1". This is a BACKREFERENCE to the capturing parentheses
   used above. Since only one set of parentheses was used, it is
   the first capture group, hence 1 is used to refer to it. Since
   this group captured one-or-more digits (see above), this is
   what is inserted into the rewritten url.


[L]         -  This tells mod_rewrite to stop processing rules
               if this one matches

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.