tags:

views:

24

answers:

1

Here is my .htaccess file

Options +FollowSymlinks
RewriteEngine on
ErrorDocument 404 /404.php

RewriteRule ^(\d*)/(.*) /page.php?id=$1&slug=$2

It all works fine. But the moment I type site.com/342/my-page/ (with the trailing slash) I get a 404.

I need the trailing slash as optional. I.e it will redirect to the correct page with or without the slash.

I tried this, but it didn't work

RewriteRule ^(\d*)/(.*)/?$ /page.php?id=$1&slug=$2

Any ideas?

A: 

.* is greedy, so it will eat your trailing slash even if it does not have to. You have to force it to stay away like this:

RewriteRule ^(\d*)/(.*[^/])/?$ /page.php?id=$1&slug=$2

This is ensure that $2 is never ending with a slash

unbeli