开发者

mod_rewrite and slash problem

开发者 https://www.devze.com 2023-02-27 00:46 出处:网络
How to r开发者_如何学JAVAedirect url`s like this http://example/foo/bar/ http://example/foo/bar to

How to r开发者_如何学JAVAedirect url`s like this

http://example/foo/bar/

http://example/foo/bar

to

http://example/foo/bar.php

Here is my rewrite rule

RewriteRule ^(.*)$ $1.php

It works with http://example/foo/bar but if the url is ending with slash a error rise (Internal Server Error) What to to do so both url types to work properly ?


It's because the / got matched in the group .*, so you call http://example/foo/bar/.php

To make both works use :

RewriteCond %{REQUEST_URI} !\.php
RewriteRule ^(.*)/?$ $1.php

EDIT: forget when we ask a file in the first place


Well, if this is really what you want to do, then:

RewriteRule  ^(.*)/?$  $1.php

I haven't tested this, but I think it works.

0

精彩评论

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