开发者

Mod_rewrite htaccess question

开发者 https://www.devze.com 2022-12-09 09:30 出处:网络
How could I take a URL like http://example.com/page.php?2342 And turn it into http://example.com/pag开发者_C百科e/?2342

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

And turn it into

http://example.com/pag开发者_C百科e/?2342

or is that not possible?


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.


Try this rule:

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消