Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 708
Cody Avatar asked Dec 13 '13 14:12

Cody


2 Answers

  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.
}
like image 170
Victor Sergienko Avatar answered Oct 24 '22 07:10

Victor Sergienko


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.

like image 37
CrazyCoder Avatar answered Oct 24 '22 06:10

CrazyCoder