Configure PhpStorm to use .htaccess

前端 未结 2 1648
有刺的猬
有刺的猬 2020-12-19 04:56

I added .htaccess (for rewriting URLs) in my project\'s root directory but it\'s not working. I checked twice, the same file is working fine in Eclipse.

2条回答
  •  情歌与酒
    2020-12-19 05:31

    1. Indeed, PHP's built-in web server will never fully support .htaccess features. Note: it is PHP's, it is NOT PHPStorm's built-in server.

    But there is a way around.

    1. Most of the time, rewrites are needed only to redirect all the nonstatic file queries to index.php. If you only need this, you can set the server's "router script" in PHPStorm run configuration to index.php.

    2. After that, a modest hack in index.php to serve static files from the drive may speed things up.

    Add to the very beginning of index.php:

    if (preg_match('/\.(?:php|png|jpg|jpeg|gif|ico|css|js)\??.*$/',
        $_SERVER["REQUEST_URI"])) 
    {
        return false; // serve the requested resource as-is.
    }
    

提交回复
热议问题