views:

32

answers:

2

If I have a url http://example.com/page.php

but I want the page to display when someone goes to http://example.com/page/

how do I go about doing that?

A: 

Try this:

RewriteEngine on
RewriteRule ^([^/]+)/$ $1.php
Gumbo
Nice, but what if I want http://example.com/page to work too (missing the trailing slash)?
kylex
@kylex: Make the slash optional with `/?` and extend your rule to let the requested URL path not end with a `.php`: `RewriteCond $1 !.*\.php$`
Gumbo
A: 

I usually use something like this:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule ^$ index.php [L,QSA]
RewriteRule ^([^/\.]+)/?$ $1.php  [L,QSA]

</IfModule>

Note the question mark after the slash. You could add that to Gumbo's example to "test" for a trailing slash (so it can be there or not).

Typeoneerror