Fix mod_rewrite for trailing slash

I've got the following .htaccess file:
RewriteEngine ON
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.+) $1 [L]

RewriteRule ^([^/]+)/([^/]+)/([0-9]+)$ index.php?action=$1&page=$2&id=$3 [L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?action=$1&page=$2 [L]
RewriteRule ^([^/]+)$ index.php?action=$1 [L]

Open in new window


Which works as intended, changing www.site.com/photos to www.site.com?action=photos behind the scenes. however if I type in www.site.com/photos/ it doesn't work and given the way this was made I'm wondering if there is an easy way to fix this? Or am I simply going to have to change the regex to include allowable characters and an optional ending slash? Thanks in advance.
LVL 10
DerokorianAsked:
Who is Participating?
 
DerokorianAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for Derokorian's comment http:/Q_27400935.html#36981548
Assisted answer: 100 points for themrrobert's comment http:/Q_27400935.html#36981450

for the following reason:

Thanks for trying themrrobert - I was able to find the answer else where tho =D
0
 
themrrobertCommented:
try adding slashdot  /. to the end of the regex part. it may need to be in parentesis
RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/.$ index.php?action=$1&page=$2&id=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/.$ index.php?action=$1&page=$2 [L]
RewriteRule ^([^/]+)/.$ index.php?action=$1 [L]

Open in new window

0
 
themrrobertCommented:
try this 2nd

either one should work
RewriteRule ^([^/]+)/([^/]+)/([0-9]+)(/.)$ index.php?action=$1&page=$2&id=$3 [L]
RewriteRule ^([^/]+)/([^/]+)(/.)$ index.php?action=$1&page=$2 [L]
RewriteRule ^([^/]+)(/.)$ index.php?action=$1 [L]

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
DerokorianAuthor Commented:
Neither works. No longer works with or without a trailing slash.
0
 
DerokorianAuthor Commented:
I've found the answer. Its to add /? to the end of each. This is my file now:

RewriteEngine ON
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.+) $1 [L]

RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/?$ index.php?action=$1&page=$2&id=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&page=$2 [L]
RewriteRule ^([^/]+)/?$ index.php?action=$1 [L]

Open in new window

0
 
South ModModeratorCommented:
All,
 
Following an 'Objection' by themrrobert (at http://www.experts-exchange.com/Q_27401018.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
SouthMod
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.