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:
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?
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.
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]
Related
I've deployed a symfony4 project on Azure, it uses IIS so .htaccess doesn't work. I've set the root folder on Azure app settings to "site\wwwroot\testproject\public" that folder contains index.php. I've tryed differents web.config without results.
If I open the app url it says: "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
but if I open the url appending /index.php it shows the content. I need a rewrite rule like symfony/apache-pack gives for apache but for IIS.
Thanks a lit
There is an extensive article on learn.microsoft.com on converting .htaccess to web.config: https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig
I won't paste the contents here since it is very extensive and I don't use Windows and you may have custom .htaccess rules.
I suggest you to identify all .htaccess config files on your install and convert them.
I've gone through phalcon's documentation and followed the tutorial provided on the official site: https://docs.phalconphp.com/en/latest/reference/tutorial.html
The problem is when I browse the project (localhost/tutorial) it shows me the directory list as
app/
public/
What am I doing wrong?
The .htaccess file for the phalcon directory structure assumes you're working at the web root, not a subdirectory. You'd need to adjust your .htaccess file accordingly if you're not going to follow their proposed directory structure. The .htaccess file they give you is designed to redirect all traffic to the web root to your /public directory thus essentially hiding the /app directory from the web. Try placing their suggested web root .htaccess file in your tutorial directory and add a line RewriteBase /tutorial/. Then place their 2nd .htaccess file in your /tutorial/public directory adjusting its RewriteBase to RewriteBase /tutorial/public/.
Alternatively, you can avoid their public directory altogether and use a safer and faster directory structure, due to avoiding extra RewriteRules, albeit less convenient, by placing your app directory below the web root and adjust your PHP to use either dirname(__DIR__) or .. to refer to the parent directory when attempting to locate your app directory.
A final approach would be to create a subdomain on your localhost, http://tutorial.localhost/, yes localhost subdomains are a great solution for allowing web root access for multiple projects without stepping on each other's toes, then you'd edit your hosts file to add a record for the fake domain mapping it to 127.0.0.1, the same as localhost. Then edit your apache config file adding a virtual host for the subdomain mapping it to a specific directory to use as your web root for that subdomain, reload apache, and presto.
Thanks for the answers...but i figured out the problem myself.
The problem was the configuration setting in apache. I changed the setting in the http.conf in apache folder by removing the # from LoadModule rewrite_module. And that worked for me. cheers!
Steps:
Go to wamp/bin/apache/apacheVersion/conf
open httpd.conf
Uncomment or remove "#" from LoadModule rewrite_module
modules/mod_rewrite.so
Working with zf2, we have configured the project successfully in local env, we deployed the same code to server, but there..only the IndexController action is working.
like www.project.com/public/ works,
but when I access other modules like
www.project.com/public/country doesn't work.
This means the mod_rewrite rules to rewrite all requests to your index.php file are not being used. Generally this means either:
The .htaccess file was not uploaded (check the public folder on the server to see if it's there)
The .htaccess file is being ignored (check AllowOverride for the vhost on the live server)
Also, really public/ should not appear in your URLs. Unless you are using shared hosting (where this can be tricky), you want to point your vhost's document root at the public folder.
In a proper Zend setup an error should come from Zend. When you get an error like this, returned from Apache, your apache configuration is not working. Your Zend application isn't even considered, i.e. the index.php in your public folder.
It's a save guess that your [public/].htaccess isn't used. Check your apache web configuration. Most likely you're missing the AllowOverride All statement which is usually inside the <Directory> statement.
And as mentioned by Tim you really should not have public/ in your path to begin with.
With the goal to install owncloud (version 6.0.3-0) on my ubuntu server (14.04), I followed this guideline:
http://doc.owncloud.org/server/6.0/admin_manual/installation/installation_source.html
After having this completed, the /var/www/owncloud folder exists with the following content:
3rdparty core index.html occ robots.txt themes apps cron.php index.php ocs search version.php config data l10n public.php settings console.php db_structure.xml lib remote.php status.php
Visiting
http://localhost
results in a site like this: https://assets.digitalocean.com/articles/lamp_1404/default_apache.png indicating, that the apache-server works.
Visiting
http://localhost/owncloud
leads to server error 404: "Not Found".
Meanwhile, I tried the installation (owncloud 6.0.3-0) on my laptop (Ubuntu 13.10) to compare results. Skipping the above guidelines, just installing owncloud using the package-manager works out of the box, while the content of /var/www/owncloud results only in config data
Since it works on my laptop, I have the suspect, that I screwed up some configuration on my ubuntu server. Even so, reinstalling apache2 (including purge) did not help.
Do you have any ideas, where to start over?
This is because Apache 2.4's default web root is /var/www/html as opposed to /var/www. ownCloud's default installation ends up in /var/www/owncloud, which is outside of the web root.
I first solved this by creating a symbolic link at /var/www/html/owncloud, but I found it cleaner to simply change Apache's document root to /var/www/owncloud. If you want to preserve the owncloud subdirectory, you can point it to /var/www and get rid of /var/www/html and its contents.
Edit /etc/apache2/sites-enabled/000-default.conf (and/or the appropriate configuration for the SSL site in the same location, depending on your setup) to point DocumentRoot to /var/www or /var/www/owncloud, whichever works for you.
I just figured this out myself, so it may warrant further configuration changes. I will update this post if/when I figure out more tweaks need to be made, but it seems to be working for me, anyway.
Also this has nothing to do with programming and really belongs on superuser.com or perhaps serverfault.com.
This would be more appropriate as a comment as I'm completely clueless as to the solution, but the strange system of SO doesn't allow me to post comments. I have an idea that may not help but just want to confirm that it's not the problem.
Have you tried the following URL?
http://localhost/owncloud/index.html
The first thing that came to mind is that there is a problem with your Default Document settings.
If the above works, you can fix it so you don't have to define the HTML file in the URL by creating a .htaccess file in your server root directory with the contents being:
DirectoryIndex index.php index.html index.htm default.html default.htm home.html
Hope this helps.
I am trying to deploy a php / codeigniter project to a shared hosting environment.
Locally I am running MAMP and all my paths are referenced thus:-
background:transparent url(/img/myimj.jpg) left top no-repeat;
When I deploy the shared host, these links do not work and to resolve them I need to add "../". Changing all these references alone would be tiresome. but codeigniter paths are also affected and I want to understand how I can have the same mapping as my local instance of MAMP apache.
Not being well versed in apache, I do not know how to resolve this issue. I am using the root public_html folder that has been mapped to my user. Is it possible to use a rewrite rule in a .htaccess to do this?
Thanks for your time.
You could use a .htaccess rewrite rule that just directs all images/css/whatever to a specific directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /path/relative/to/web-root/
RewriteRule /?([^/]+)\.css css/$1.css
RewriteRule /?([^/]+)\.(jpe?g|png|gif) images/$1.$2
</IfModule>
This is assuming all your images are in a folder called images and all the style-sheets in a folder called css.
In this scenario, it would be best call the images and stylesheets in your code/css using an absolute path. That way images would be cached properly. Even tho the server redirects all the images to the same directory, the client would not see that. So if the same image was called using a relative path from two files in different positions of the tree, the client would see those as two different images and not cache it properly
If your "shared" environment means that you're sharing a DOCUMENT_ROOT, then you'll have to be careful with a .htaccess file - as this will be the .htaccess file for everyone. Otherwise if you have a Virtual host, then what would it take to upload you images into /path/to/document/root/img?
Thanks for your input on this.
Having got through to the web hosting company, I have since realized that the behavior of a virtual host differs if you do not have an ANAME pointing to it. On adding one the folder public_html is mapped as web root as it should be.