Configure PhpStorm to use .htaccess

前端 未结 2 1630
有刺的猬
有刺的猬 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.
    }
    
    0 讨论(0)
  • 2020-12-19 05:38

    Do you use the same server/configuration when working with PhpStorm and Eclipse?

    As it was explained in the comments, it has nothing to do with the IDE, but with the web server (Apache) and its configuration.

    You can edit .htaccess with any editor, if this virtualhost/directory configuration has AllowOverride All, ModRewrite is enabled and your rewrite rules are correct, it will work just fine.

    You need to ensure that your PHP files are served from the correctly configured web server.

    0 讨论(0)
提交回复
热议问题