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.
Related
I have my website inside the following path on my remote web hosting server:
~/public_html/website/app
and need to find a way to show it when typing:
mydomain.com
so without the need of typing the full path:
mydomain.com/website/app/
One solution that came to my mind was to create a index.php file inside my root folder to automatically redirect to ./website/app/:
<?php
header('Location: ./website/app/');
exit;
but then I need to rewrite the URL in order to go from:
mydomain.com/website/app/
to:
mydomain.com
and I did not find a way to do that!
So, what do you think I should do to obtain that result and show my website under /website/app/ when accessing:
mydomain.com
and do not show the /website/app/ folder names?
Thanks a lot!
edit:
I was forgetting that I also have the website/server path so I need a rule that keeps valid the requests containing mydomain.com/website/server/.
Plus, I cannot use:
Options +FollowSymLinks
on my hosting (for security reasons), it's overridden by:
Options +SymLinksIfOwnerMatch
You have two options to do that.
If you just want to show the /website/app directory for your root url / then you can use DirectoryIndex directive .
DirectoryIndex website/app
This will show you the index file from /website/app folder if you visit the your root URI ie : example.com/ .
If you want to server files and directories from the /website/app instead of the / folder then you can use a RewriteRule that rewrites your root level requests to the subfolders .
RewriteEngine on
RewriteRule !website/app /website/appâ„…{REQUEST_URI} [L]
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
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 :)
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!