How to disable parent htaccess rules in a specific folder - apache

I have an htaccess in the main folder. I don't want to apply the main htaccess to a specific folder inside the main folder.
--Main Folder
.htaccess
some folder
another folder --> don't want htaccess to apply here
some files
...
How can I do this?

Just create a one liner .htaccess in that specific folder where you don't want rules from main .htaccess to apply with:
RewriteEngine On

Related

Auto index showing directories only

If I add Options +Indexes in .htaccess this will display all files and subdirectories. However, I would like to exclude files for the current directory. i.e. display directories only for the current directory and display files and directories for any subdirectories.
Is this possible in .htaccess or will I need to write my own script to generate the directory index?
According to the comment of CBroe above, I've maked this approach tested in debian apache2 in .htaccess:
Options +Indexes
IndexIgnore *.*
This will ignore files with a file extension such as file.html. As we usually not name a directoty with a dot extension, so directories will be shown.
Please consult also apache autoindex reference http://httpd.apache.org/docs/2.4/mod/mod_autoindex.html .

.htaccess rewrite to folder

Is it possible to rewrite url to point to the "last" folder in directory?
Folder structure:
/path/to/site
/path/to/site/0.1.0
/path/to/site/0.2.0
/path/to/site/0.3.0
http://host/path/to/site/0.1.0 show content of folder /path/to/site/0.1.0
http://host/path/to/site/0.2.0 show content of folder /path/to/site/0.2.0
http://host/path/to/site/0.3.0 show content of folder /path/to/site/0.3.0
http://host/path/to/site shows content of folder /path/to/site/0.3.0

Deploy on Shared Web Host

I have a simple question but I just can't find a straightforward answer anywhere.
I'm not very familiar with apache .htaccess and now I should deploy a ZF2 app on a web host that doesn't allow me to change the website root folder.
I have a standard project structure so my index.php file is located inside the /public folder, like this:
www.mydomain.com
root/ <--- I can't set root to /public folder
/config
...
/module
...
/public
.htaccess
index.php
...
/vendor
...
...
This is from the ZF2 skeleton app.
Please I need a workaround, I'm sure this is a pretty common problem that many ZF2 developers already tackled. I think I should add a .htaccess file to /root but I don't know how to write one that would work in this case.
As always any help is much appreciated,
Dan
In order to make this work you have to take everything from the /public folder and put it inside your web root. The file index.php from the skeleton app must be edited to take account of its new position.
First remove the line:
chdir(dirname(__DIR__));
Because its purpose is to set the current directory to the web root which we are already inside.
Second you have to either:
Replace the line require 'init_autoloader.php' with require 'vendor/autoload.php' (if using composer).
OR
Inside your .htaccess set the ZF2_PATH env variable to where zf2 is installed on your server:
#First line of your .htaccess
SetEnv ZF2_PATH path/to/zf2
Now it should be working.
Make it better
With the above setup you'll have to put all your public folders inside the web root. If you, like me, don't like that just continue reading.
You can put your public folders (e.g., /js, /css) inside /public (index.php and .htaccess still need to be in the root) by simply telling zf2 your new base_path. This is what is used by the basePath() view helper inside your view scripts. You simply need to add the following to your config:
'view_manager' => array(
'base_path' => './public',
),
And the basePath() view helper will output the correct urls.
Make it even better
The last problem with this setup is that your app files are accessible from the web. To fix this I put everything I want to hide inside the /private folder. You end up with a project structure similar to this:
/root
/private
/config
/data
/module
/vendor
.htaccess <-- You have to create this one
composer.json
composer.lock <-- Created by composer after install
composer.phar
/public
/css
/js
.htaccess
index.php
Inside the /private folder you have to create a new .htaccess file and put this line inside it:
Deny from all
This makes everything inside the folder not accessible from the web.
With this change you have broken your app. Infact inside /private/config/application.config.php you have to adjust the module_paths config:
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
),
You have to prepend /private to the paths:
'module_listener_options' => array(
'module_paths' => array(
'./private/module',
'./private/vendor',
),
),
This will make your app run once again. Now you can deploy your ZF2 apps to shared web hosts and retain a clean project structure.

Symlink, Am I Missing Something?

I'm trying to symlink my public folder with a index.php file in it to the httpdocs folder where the public folder is also placed.
When I try and Symlink the public folder I get an error alerting me that the public folder name is already taken. I've also tried Symlinking the index.php file itself which worked but broke the functionality of the site.
Here is the command I'm using when Symlinking the public folder.
ln -s /var/www/vhosts/mysite.co.uk/httpdocs/public /var/www/vhosts/mysite.co.uk/httpdocs
Here is the command I used when Symlinking the index.php file.
ln -s /var/www/vhosts/mysite.co.uk/httpdocs/public/index.php /var/www/vhosts/mysite.co.uk/httpdocs
tldr: I want to use the index.php in the public folder as the index.php file when a user visits my site without having to use mysite.co.uk/public/index.php. The index.php file has to remain in the public folder.
If I understand correctly, you want to access index.php from httpdocs/public, and that folder already exists (as the error in the first case informs). You can link the file to that (exisitng) folder:
ln -s /var/www/vhosts/mysite.co.uk/httpdocs/index.php /var/www/vhosts/mysite.co.uk/httpdocs/public/index.php
Note that you need to specify the file itlsef that you want to link
I've managed to get it to work! I used a soft symlink on public/index.php in the httpdocs folder to make a index.php file also in the httpdocs folder.
ln -s /var/www/vhosts/mysite.co.uk/httpdocs/public/index.php /var/www/vhosts/mysite.co.uk/httpdocs/
I then added a .htaccess file to the httpdocs folder with the following...
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
Thank you to #Attila for sticking with me and helping out!
Solution (if all files are required in …/public and …/httpdocs.
move your data from /var/www/vhosts/mysite.co.uk/httpdocs/public to /var/www/vhosts/mysite.co.uk/httpdocs
symlink /var/www/vhosts/mysite.co.uk/httpdocs to …/public
Command: ln -s /var/www/vhosts/mysite.co.uk/httpdocs /var/www/vhosts/mysite.co.uk/httpdocs/public
Cons:
infinite recursion, for instance /var/www/vhosts/mysite.co.uk/httpdocs/public/public/public/public/
It is not possible to symlink to an existing file/directory. If it would be possible, you would break your tree structure. In fact you are trying to link a directory to its parent. How should your system resolve overwritten paths?
Example:
You have a file /a/b/c and it would be possible to do the following:
ln -s /a/b /a
How should the system resolve the now not reachable file /a/b/c?
Move your data into the desired directory instead of trying to break your file tree.
It is possible to mount data to existing directories (original data will be unreachable until unmount), but this would not help in your case.

include .htaccess in another directory into a main .htaccess

I was looking at making a folder structure like this
htdocs
|--app
|-- myProject
|-- index.php
|-- settings.ini
|-- .htaccess (project)
|--core
|--index.php
|--config.ini
|--.htaccess (main)
I waned some global .htaccess rules in the main .htaccess file but I wanted some project specific rules in the project .htaccess
Is there a way I can have both .htaccess fils co-exist? or have the project .htaccess file included in the main .htaccess?
I know in apache you can include files, because in my httpd.conf i have an include statement to include .conf files outside of the directory.
On my server I have exactly what you have here. One .htaccess file for the htdocs folder and one for another site.
I never had any problem, it seems that the .htaccess for the project overrides the .htaccess for htdocs.