-1

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Bas
  • 2,106
  • 5
  • 21
  • 59
  • check out http://stackoverflow.com/questions/9282124/deny-direct-access-to-a-folder-and-file-by-htaccess – Dave Sep 12 '14 at 19:58
  • @Dave It's the same thing, its giving me a 404 error. Because there exists no index.php file. But when there is, it just works. – Bas Sep 12 '14 at 20:05
  • Did you tried `Options All -Indexes` ? –  Sep 15 '14 at 06:52
  • http://coolestguidesontheplanet.com/redirecting-a-web-folder-directory-to-another-in-htaccess/ – hakki Sep 15 '14 at 06:59
  • @vlzvl Yes, and i didnt work aswell.. :\ could it be because of i dont get actually the file explorer system? Like when i open it via my browser. (The apache server) – Bas Sep 15 '14 at 07:07
  • @hakiko I knew this already, thanks for the great article though :). But it just doesnt seem that it reacts on the file, whatever code is in it. – Bas Sep 15 '14 at 07:25
  • possible duplicate of [Configure phpstorm to use .htaccess](http://stackoverflow.com/questions/20569493/configure-phpstorm-to-use-htaccess) – Victor Sergienko Mar 05 '15 at 17:02

2 Answers2

1

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.

BayssMekanique
  • 894
  • 1
  • 14
  • 27
  • This didn't work, I tried it with my apache server on, without running phpstorm. And still the same problem occurs. – Bas Sep 13 '14 at 13:08
  • When I access the folder `localhost/app`, and there is no index file in it, it gives me an `404` error, with text beneath it `Index file is not found`. Also, the version of PHPstorm is being shown on that same screen. Whenever I put an `index.php` file inside that `localhost/app` folder. And i access that folder, it just loads that file, without any errors. – Bas Sep 14 '14 at 13:16
  • Can you post your entire `.htaccess`? – BayssMekanique Sep 14 '14 at 21:35
  • Sorry but i already did.. Those are all the contents. It doesnt seem that the phpstorm server (63342) has support for this htaccess file? – Bas Sep 15 '14 at 05:41
  • Alright, i figured out that when i place my project files into the `htdocs` folder from `xampp`, and then go to that with any contents inside the `.htaccess` file, it works. Is there any way phpstorm can do this on its own server? (63342) So i dont have to move all the files every time – Bas Sep 15 '14 at 16:30
  • No. 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 http://confluence.jetbrains.com/display/PhpStorm/Installing+and+Configuring+XAMPP+with+PhpStorm+IDE#InstallingandConfiguringXAMPPwithPhpStormIDE-IntegratingtheApacheserver – BayssMekanique Sep 15 '14 at 17:14
  • Aw okay, is deploying the only workaround? Because i have seen some plug-in for phpstorm that says it has support for the .htaccess file. Or is that only about the code hinting? Btw if you can edit that in your answer i can accept it :) – Bas Sep 15 '14 at 17:59
1

Using mod_alias is even easier:

Redirect 301 /app /new_directory

But if you have rewrite rules in your htaccess file already, then you need to stick with using mod_rewrite:

RewriteRule ^app/(.*)$ /new_directory/$1 [L,R=301]
hakki
  • 6,181
  • 6
  • 62
  • 106