how to use remove file extension from url using alias - apache

I want to remove the file extension for some of my files using Alias in my Apache site config file, but i just can't get it to work.
Here is an example:
Alias "/alias" "/the/real/path"
I have also tried this:
Alias /alias /the/real/path
With both i have tried the full path and the relative path from the root directory.
Does any one know how to probaly use Alias to do this?

Be sure to set AllowOverride All in the Directory config.
Example:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Related

How to hide everything but public folder(s) having multiple laravel projects ? (apache)

I have multiple laravel projects in my htdocs folder:
htdocs/laravelProjectA
and
htdocs/laravelProjectB
So that if i want to access a laravel route of lets say laravelProjectA the corresponding url will be:
localhost/laravelProjectA/public/myRoute
The problem is that all the laravel files and folders are inside the htdocs folder and therefore accessible to the Web, meaning that i can enter, for example:
localhost/laravelProjectA/.env
and view all the sensible data.
How can I hide all the files and folders but the public folder from each project using Apache? So that localhost/laravelProjetA/.env, localhost/laravelProjectA/.gitignore, and every request for the other files result in a 404 error, or similar.
I know i can leave only the public folder inside the htdocs folder for each project and move the other files and folders somewhere else and then change the public/index.php file, but I want to use apache to hide those files in order to have each project in a single directory.
You have to edit the /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
to
<Directory /var/www/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Server will stop showing files

Directory Index with Default Handler

If I use the SetHandler default-handler option, I can no longer have an index for all the files in the directory. That is, Options +Indexes breaks. Is there a way to fix this or is there an alternate way to listing files in a directory using Apache?
You don't need an index for all the files in the directory. Are you trying to do
/index.php
or run some other script and when you do
/
you want the index of the directory? To see a list of files in a directory use this
<Directory /this/is/the/list/directory>
Options +Indexes
</Directory>
Have a look here...
https://wiki.apache.org/httpd/DirectoryListings
This seems to work:
<Directory /srv/html/test>
<Files ?*>
SetHandler default-handler
</Files>
</Directory>
It should set the default handler on all files with a filename of 1 character or longer. Autoindexing still works (if you have that configured, that is).

How to make a subdirectory act like a isolated domain using Virtual Host Directory and Alias

I'm hosting localhost/~username/website and I have /subfolder/filename.txt
right now that reference goes to the root but I want it to not have that privilege and to go to localhost/~username/website/subfolder/filename.txt instead.
I'm trying this below but it's not working in my httpd-vhosts.conf. This is inside my
Alias /~username/website "/Users/username/Sites/website"
<Directory "/Users/username/Sites/website">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
I ended up create multiple VirtualHost *:443 and :80 respectively with servernames that were different

wamp alias error, spaces in the directory name

I have two alias, one works and one not. I think the problem with the wrong one is that has spaces in the directory name because is the only difference.
This works:
Alias /test/ "c:/test/noteboardapp/"
<Directory "c:/test/noteboardapp/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
This doesn't work:
Alias /noteboard/ "c:/Documents\ and\ Settings/odedios/Mis\ documentos/Google\ Drive/Trabajo/www/noteboardapp/"
<Directory "c:/Documents\ and\ Settings/odedios/Mis\ documentos/Google\ Drive/Trabajo/www/noteboardapp/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
I have the error: "You don't have permission to access /noteboard/ on this server."
I've scaped the spaces with "\" If I don't do the server doesn't run.
What is wrong?
Thank you!
Oscar.
EDITED: I've found the solution here Use Google Drive Directory as Apache Virtual host
The problem was that I was using a google drive folder and I have to change the permissions to access to this folder:
Right click 'Google Drive' Folder -> Properties -> Security Tab -> Advanced -> Change Permissions... -> Check 'Include inheritable permissions from parent folder'.
With this code:
Alias /noteboard/ "c:/Documents\ and\ Settings/odedios/Mis\ documentos/Google\ Drive/Trabajo/www/noteboardapp/"
You're telling Apache to find this directory:
C:\Documents\ and\ Settings\odedios\Mis\ documentos\Google\ Drive\Trabajo\www\noteboardapp\
Just remove all those bogus backslash characters.
Edit: White space is not the only difference between your two settings. The second alias points to a user profile, which is likely to be protected so only user odedios can read it.

Cannot disable Directory Listing in httpd.conf

I just installed XAMPP on my personal CentOS box and when I try to disable Directory Listing I get an Apache error when restarting. My httpd.conf file looks like this after I make the changes:
httpd.conf
Alias /bitnami/ "/opt/lampp/apache2/htdocs/"
Alias /bitnami "/opt/lampp/apache2/htdocs"
<Directory "/opt/lampp/apache2/htdocs">
Options -Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Error
XAMPP: Starting Apache...fail.
AH00526: Syntax error on line 5 of /opt/lampp/apache2/conf/httpd.conf:
Either all Options must start with + or -, or no Option may.
I have tried removing Indexes all together and I can still see my directories. Maybe I'm in the wrong file, but from what I've read disabling directory listing has to be made here or .htacces (which I am trying to avoid.) In case it comes up I have made sure to restart XAMPP every time I made changes.
The error message is pretty clear. To rephrase / show examples:
# relative to whatever lower precedence section applies
Options -Indexes
If your goal is to turn off indexes. If you want to make sure FollowSymlinks is also set, put a + in front of it:
# relative to whatever lower precedence section applies
Options -Indexes +FollowSymlinks
If you want to turn everything but FollowSymlinks off:
# not relative
Options FollowSymlinks
Please go to file: /opt/lampp/etc/httpd.conf
and either comment the line like this:
#Options Indexes FollowSymLinks Includes ExecCGI
or edit like this
Options -Index
For Windows machine: Do same editing in file /apache/conf/httpd.conf
I put a "+" in front of word "FollowSymlinks" to have success.
And replace this lines:
AllowOverride All
Order allow,deny
To:
Require all granted
I hope to help you!
You can also use:
sudo a2dismod autoindex