Why doesn't this disable directory listing for my site? - apache

I'm using Options –Indexes in a .htaccess file in the directory I want to disable listing, but still when I go to the directory I can see all the files in that directory. What am I doing wrong? (Apache server).

Is it possible you have DirectorySlash turned off? It makes it so requests for directories that are missing the trailing slash gets redirected to the same directory with the trailing slash. By default it is on, but if it's turned off, it has a strange side effect that allows listing of directories regardless of the Indexes options:
Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where mod_autoindex is active (Options +Indexes) and DirectoryIndex is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file. But a request without trailing slash would list the directory contents.

Related

Redirect a forbidden URL in Apache

I would like to move an entire directory and its subdirectories from one Apache server A to another Apache server B, and then create a redirection from A to B.
i.e.
http://server_a.com/docroot/dir to http://server_b.com/docroot/dir.
This is what I did:
I copied the files and directory structure under dir from A to B
I deleted the directory dir on A
I created a rule in docroot/.htaccess on server A that reads
Redirect permanent dir/ http://server_b.com/docroot/dir/
But when I go to http://server_a.com/docroot/dir/path/to/file/index.html, I get a 403 Forbidden, even if the target page http://server_b.com/docroot/dir/path/to/file/index.html is up.
I know that the .htaccess is read by Apache, because it correctly controls other parts of server_a. I am not root on these servers. I have also tried with a RewriteRule, with the exact same results.
How should I go about creating a redirect in this case? Thanks.
If you have mod_rewrite enabled than you can do this
RewriteEngine On
RewriteRule ^/?docroot/dir(/.*)?$ http://server_b.com/docroot/dir$1 [R=301,L]
Put it in your .htaccess file in the Document Root directory http://server_a.com/.
Note:
Delete you Browser cache first.
You'll need the leading / in the old URL. Like this:
Redirect permanent "/dir" "http://server_b.com/docroot/dir/"
See the mod_alias docs for more details.

Redirect request to folder with .htaccess

How can I set .htaccess to make
http://www.example.com/folder
go to (assuming this is not made automatically)
http://www.example.com/folder/ ?
For existing directories, Apache already provides a configuration option via mod_dir. Add the DirectorySlash directive to your main configuration file, or otherwise the root .htaccess file.
DirectorySlash on
See the documentation.

Shutting down a website using HTaccess does not work

OK, it's very simple but it does not work. I have a wiki site where the root contains an index.php file and the subdirectories contains the content of the wiki (I use PMwiki, so no database is required)
I want to temporarity shutdown the website and make it unaccessible by using an nice HTML page to display the shutdown message. I could rename the index.php file, but the rest of the files in the subfolder will remain accessible.
The first thing that worked but which is not elegant is restricting the whole site with a password in the htaccess using "Require valid-user" and all it's other command. The problem is that I cannot display a nice shutdown message as an HTML file.
Else I tried renaming the index.php file to something else like site.php. Creating a index.html file as a message and using a script like this:
Order Deny, allow
Deny from all
<File "index.html">
Allow from all
</File>
In that case, the index.html file is accessible, but it must be manually typed in the URL, it will not use this file by default. I tried adding DirectoryIndex directive like this
DirectoryIndex index.html
But it still does not work.
So first is there a way to make the user only see 1 page in particular and block everything else.
Second, doing so makes the site unaccessible to me. So is there a way to passords restrict the whole directory structure except for a specific index.html file. So that I could type url/site.php and be able to enter my website using an htaccess password.
Thanks for any help
Just this rule in root .htaccess should be able to handle this:
RewriteEngine On
RewriteBase /
RewriteRule !^shutdown\.html$ shutdown.html [L,NC]
Now you can keep custom HTML content in /shutdown.html. Keep in mind you need to use inline css/js since it will also rewrite css/js requests to /shutdown.html file.

index.php/argument not found - strange issue with apache

when passing parameters after index.php its showing 404 error .. its apache error not the cms
but there is no problem accessing index.php directly
File does not exist: /home/me/web/test/index.php/a
File does not exist: /home/me/web/test/index.php/home
File does not exist: /home/me/web/test/index.php/contact
problem doesn't related to mod_rewrite because I am getting same error when index.php is in the URL ..
using .htaccess and mod_rewrite and removing index.php from url doesn't help :(
You're not making totally clear where those URLs come from, but from the looks of it, your web server's AcceptPathInfo directive isn't "On".
This directive controls whether requests that contain trailing pathname information that follows an actual filename (or non-existent file in an existing directory) will be accepted or rejected. The trailing pathname information can be made available to scripts in the PATH_INFO environment variable.

.htaccess handling leading forward slash

I have a project which I wish to place in a sub-directory of a web root directory.
So if I had:
/public_html as the web root directory
I want the project to live in:
/public_html/myproject
Now, the project will eventually live in the root folder, so I want to make as few code changes as possible, but during testing it must stay in the sub-directory.
The issue is with the following:
<img src="/images/image1.png" alt="" />
This works fine when the project is in the document root, because the leading forward-slash is doing it's job.
However, when the project is in the sub-directory, the / takes the relative path back to the web root folder.
How can I alter .htaccess to prevent this? I need the leading forward slash to reference the "/myproject" folder instead.
Any ideas on how it can be done?
If you have the apache module mod_rewrite enabled, you could add the following to your .htaccess file in the root folder.
RewriteEngine On
RewriteBase /
RewriteRule ^images(.*) /myproject/images/$1
You can find more information on this here:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html