Cody
Cody

Reputation: 2649

Configure PhpStorm to use .htaccess

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.

How do I configure PhpStorm to use .htaccess?

Upvotes: 8

Views: 8837

Answers (2)

Victor Sergienko
Victor Sergienko

Reputation: 13475

  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.
}

Upvotes: 3

CrazyCoder
CrazyCoder

Reputation: 401887

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.

Upvotes: 1

Related Questions