views:

31

answers:

3

How could I take a URL like http://example.com/page.php?2342

And turn it into

http://example.com/page/?2342

or is that not possible?

+1  A: 

You don't need mod_rewrite for that. You can use MultiViews.

Options MultiViews

in addition to your other options. You need mod_negotiation enabled in your server.

From the docs:

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

MultiViews may also apply to searches for the file named by the DirectoryIndex directive, if the server is trying to index a directory. If the configuration files specify

DirectoryIndex index then the server will arbitrate between index.html and index.html3 if both are present. If neither are present, and index.cgi is there, the server will run it.

If one of the files found when reading the directory does not have an extension recognized by mod_mime to designate its Charset, Content-Type, Language, or Encoding, then the result depends on the setting of the MultiViewsMatch directive. This directive determines whether handlers, filters, and other extension types can participate in MultiViews negotiation.

Vinko Vrsalovic
+1: 'Cuz it's cool, and I didn't know about it.
Satanicpuppy
A: 

Try this rule:

RewriteRule ^([^/.]+)/$ $1.php
Gumbo
A: 

Is the /?2342 necessary, or could you do it like this?

RewriteRule page/(\d*) page.php?id=$1

Otherwise it would be

RewriteRule page/\?(\d*) page.php?id=$1

(I think that works, anyhow. I can't test it at the moment.)

davethegr8