Running PHP without extension without using mod_rewrite?

前端 未结 3 2033
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 11:34

Using Apache 2.2 and PHP 5, what\'s the best way to run PHP without the .php extension? For example, I have a script called app.php and I like to i

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 11:53

    The short answer is that you aren't going to be able to do this the way you want to. PHP is going to require SOME extension in order to execute the files so you might as well leave it as *.php.

    Unless you use mod_rewrite you are going to have to call the files using the full file and extension.

    That is the beauty of mod_rewrite--it lets you do just such a thing.

    I would pose the question back to you--why can't you use mod_rewrite? Is it an environment issue, a choice, are you using Lighttpd (lighty)?

    Extension

    Wrap your rewrite rules in something like this to keep it from blowing up if the server doesn't support mod_rewrite:

    
    // DO REWREITE HERE
    
    

    If you believe it to be a security concern or something equally valid then you could also do the following check and send them to a custom 404 or even your documentation and give them examples of how to enable mod_rewrite and explain the need, etc. This second check is optional though--if you don't use it the users will simply see the .php extension but your pages should still work.

    
        ErrorDocument 404 /application/errors/404.php
        // ERROR 404 ABOVE OR DO ANOTHER DIRECT REDIRECT TO AN INFORMATION PAGE
    
    

提交回复
热议问题