Matt Himsl
Matt Himsl

Reputation: 49

mod_rewrite with optional trailing slash (No Content displaying)

On my website. I have mod_rewrite enabled (Below is the code):

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.*)/?$ index.php?ToDo=$1 [L,QSA]

When accessing my website with the above .htaccess file contents, viewing the pages with the backslash gone, will show the desired content of each page (organized by conditional statements [Ex. if($_GET['ToDo'] == 'about'){}]).

However, when viewing the page with the trailing slash, it doesn't display the content (organized by conditional statements [Ex. if($_GET['ToDo'] == 'about'){}]). What am I missing?

Upvotes: 1

Views: 63

Answers (1)

anubhava
anubhava

Reputation: 785631

Try this modified regex:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/([^/]+)/?$ index.php?ToDo=$1 [NC,L,QSA]

Upvotes: 1

Related Questions