Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache .htaccess <Directory not allowed here

I run XAMPP and I'm trying to learn how .htaccess works. I have a file structure that looks something like this:

/parent
    /foo
    /bar
    .htaccess

I simply want to change all foo requests to bar with a GET parameter appended after them. For example:

foo/
foo/hello.php

turn into:

bar/?test=yes
bar/hello.php?test=yes

When I try to put the <Directory> directive in my .htaccess file:

<Directory "/foo">
    Options +Indexes
</Directory>

I get the following error log:

[Tue Sep 19 17:23:58.356362 2017] [core:alert] [pid 6336:tid 1900] [client ::1:60018] C:/xampp/htdocs/parent/.htaccess: <Directory not allowed here

I checked my httpd.conf file and everything is alright. I'm sure because if I change the contents of the .htaccess file to simply:

Options -Indexes

It correctly displays a 403 error. If I replace the - with +, it shows the directory listing.

What am I doing wrong?

like image 653
dodov Avatar asked Sep 19 '17 14:09

dodov


People also ask

Why is my htaccess file not working?

Improper syntax being used It is quite common for a syntax error to be the reason for an . htaccess file not working. If you are familiar with how to read and configure . htaccess rules, double check your configuration.

Where is .htaccess file in Apache?

htaccess file can be found at /opt/bitnami/APPNAME/. htaccess. Some applications do not have the /opt/bitnami/apache2/conf/vhosts/htaccess/APPNAME-htaccess.


2 Answers

<Directory> directive is not allowed in .htaccess and for meeting your requirements you don't even need this in .htaccess.

You can use this rule in site root (parent) .htaccess:

RewriteEngine On

RewriteCond %{QUERY_STRING} !(?:^|&)test=yes(?:&|$) [NC]
RewriteRule ^foo/(.*)$ bar/$1?test=yes [NC,QSA,L]
like image 84
anubhava Avatar answered Oct 02 '22 18:10

anubhava


<Directory.. is not allowed in .htaccess according to the manual. You can have it only in server config and virtual host. You should use mod_rewrite instead.

like image 1
akond Avatar answered Oct 05 '22 18:10

akond