开发者

mod_rewrite beginner: map files to php files

I'm trying to write a simple rule such that:

/page gets implicitly routed to /page.php. Inversely, I'd like any direct access to /page.php to be开发者_如何学Go redirected in the address bar to /page.

Currently I have:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

But that does not handle the 2nd case. How can I modify it?


You have to treat your second rule before your first one. Try this:

RewriteEngine on
RewriteRule ^(.*)\.php$ http://domain.com/$1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜