开发者

mod_rewrite beginner: map files to php files

开发者 https://www.devze.com 2022-12-20 18:36 出处:网络
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 /pag

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

精彩评论

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