• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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.
0
Derokorian
Asked:
Derokorian
  • 3
  • 2
2 Solutions
 
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
 
DerokorianAuthor Commented:
Neither works. No longer works with or without a trailing slash.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now