Search code examples
phpapache.htaccess

.htaccess file won't respond on localhost:63342 in PhpStorm


I'm using the IDE PhpStorm 7.1.4 and trying to make an .htaccess file to stop users from going into a specific directory.

My folder structure is like this:

enter image description here

I want to make it so that users can't go in the /app folder or any folders inside that folder. For this, I've figured out that I can use this piece of code inside .htaccess:

Options -Indexes

I'm using the PHP web server from PHPStorm itself (which goes to localhost:63342/projectname/folderinproject/etc/etc/).

Problems

  • When directing to the page to the /app folder, I get an 404 error, saying the index file doesn't exist.

  • When I have made an index.php file inside the /app folder, and I am redirecting to the /app folder, it just loading up the index.php.

  • When doing this with just a normal HTML project and opening the index.html via my windows explorer, the same problem occurs

Question

How can I make it so that my project would actually respond on the .htaccess file and wont allow me or other users to go into the /app folder?


EDIT

I figured out that when I copy all my files from my project to the c:\xampp\htdocs\ folder and turn on my Apache server inside of XAMPP, the .htaccess file is working whenever I open it via my regular browser (without selecting index.php in PhpStorm and choosing Open in browser...).

Is there any way I can do this same thing in PhpStorm without moving all the files?


Solution

  • If you are using the default configured web server, you are actually using PHP's new web server feature, which doesn't listen to .htaccess files. Only Apache listens to .htaccess files.

    If you are wanting to test this functionality, you can either setup a VM running Linux and test, or setup WAMP on your system and run from there.

    EDIT 1


    Ok, can you add a little more detail about the exact problem? When you access localhost/app/ it is displaying the index.php file, instead of the 404. Does the application work entirely through the index.php file? If so, is the index.php file in the app or public?

    EDIT 2


    Ok, here's what you need to do. Place an .htaccess file in the root of your app directory. Clear the contents of this .htaccess and place the line DENY from ALL. You can keep the .htaccess file in the root of the project.

    EDIT 3


    PHPStorm is going to use the PHP Engine's web server. If you add the XAMPP location as a deployment path, it's fairly quick to deploy to. You can even setup PHPStorm to automatically deploy files to the XAMPP location on save. Here's the walk-through on the JetBrains site JetBrains Config.

    The .htaccess plugins are mainly for editing and formating, not for modifying PHP Engine's server environment.