I've disabled browsing directories (-Indexes) and enabled the option for users to visit pages with and without .html file extension (+MultiViews). Like this:
Options -Indexes +MultiViews
It seems that that is causing a 403 'Forbidden' error with this url:
example.com/blog
when there is a directory called blog and a a file blog.html.
How do allow access to /blog.html without the extension in the url, without allowing browsing access to /blog/?
You need to turn off directory slash on your server in order to access the file of the same name as directory.
Add the following line to your htaccess file
DirectorySlash off
See the official documentation of DirectorySlash on apache mod-dir page
https://httpd.apache.org/docs/2.4/mod/mod_dir.html
Related
I have a website running on a server. It's just an index.html with a hello world text. Also, I have a folder named /vpn which contains various txt files and an index.html file.
If I try to access the URL domain/vpn, it shows me the content of index.html.
I just need to show the files inside the folder vpn when the user tries to access domain/vpn.
I created an .htaccess file with the next content in the root:
RewriteEngine on
<If "%{REQUEST_URI} == '/vpn/'">
DirectoryIndex disabled
Options +Indexes
</If>
When I try to access to vpn, it shows me a 404 error, the requested URL was not found on this server.
.htaccess is applying the DirectoryIndex rule (If a delete it, it shows me index.html content again), but not the Options +Indexes one.
I tried the same example in localhost (with XAMPP) and it's working fine.
What can be the problem?
PD: This is the content of apache2.conf file:
When I try to acces to vpn, it shows me a 404 error, the requested URL was not found on this server.
If you are getting a "404 Not Found" then it would imply that mod_autoindex is not actually installed on your server (consequently Options +Indexes has no effect - although it would seem from your server config that Indexes is perhaps already enabled).
mod_autoindex is the module responsible for generating the directory listings.
I created an .htaccess file with the next content in the root:
Personally, I would create an additional .htaccess file in the /vpn directory instead:
DirectoryIndex disabled
Options +Indexes
And disable Indexes (and set DirectoryIndex) in the root .htaccess file.
NB: RewriteEngine has no place here, unless you are overriding a parent config.
If I try to access the url "domain/vpn"
Note that you should be requesting domain/vpn/ (with a trailing slash). If you omit the trailing slash then mod_dir issues a 301 redirect to append it.
My project name is funfeesa and all client side pages are contains in "client" folder. But I want to access then without to write client folder in the url.
just like below:
localhost/funfeesa/index.php
I have tried many rules in .htaccess file but nothing is working fine.
can anyone help me?
#prevent directory listing
Options -Indexes
IndexIgnore */*
#follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^funfeesa/index.php(.+)?$ funfeesa/client/index.php/$1
Try to access your .htaccess file as above
Still if it doesn't work try by removing index.php from above rules but I think It should work :)
In my application I have a file called sampleaudios.php
My URL look like this
www.test.com/sampleaudios.php
But I want my url to be www.test.com/sampleaudios because my client forgot to add .php in that and the url has been mailed to customers.
Kindly help me to achive this.
You don't need a rewrite rule. Just add this line in your .htaccess:
Options +MultiViews
Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
When I browse to http://www.example.com I want to be redirected to http://www.example.com/home.html,
When I browse to http://www.example.com/index.php I want to be redirected to http://www.example.com/index.php,
How can I do that?
Hy ,
Just add the following line in you .htaccess file
DirectoryIndex something.html
where something.html will be your index page
As an extra note - see this page from docs on how to manage your .htaccess file.
Take a look at the DirectoryIndex command:
http://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex
It allows to configure what files are tried when a directory is requested. It also allows to add several options to be tried. This allows flexibility whilst you can still keep control over the options.
When a URL specifying only a directory is requested
eg.: http://www.domain.com/directory/
Apache looks for file names by default (in the order they appear):
index.html
index.htm
home.html
welcome.html
The .htaccess directive DirectoryIndex can be used to override this behavior. In your .htaccess file, type the following line:
DirectoryIndex index.php index.html
Has anyone had an issue where you try and do a redirect of a .pl file and that file just shows up as forbidden?
Here is an example of what I'm trying to do:
(http://www.oldsite.com/folder/sample.pl)
needs to redirect to...
(http://www.newsite.com/newpage/)
Here is what I have put in the .htaccess file which is located in folder on the old site (because I don't have access to the web root .htaccess file):
#the first line should allow the pearl file extension to execute
Options ExecCGI FollowSymLinks
RewriteEngine on
RewriteRule ^sample\.pl$ http://www\.newsite\.newpage/ [R=301,NC]
Though, I only get a forbidden page when I go to (http://www.newsite/folder/sample.pl). Even without the .htaccess file in place I still get a forbidden page. It's only .pl files that cause this forbidden page. If I go to any of these fake pages (sample.asp, sample.jsp) they bring up the proper "Page Not Found" message.
Can anyone think of any ideas to get around this .pl extension issue?
Thank you!