Change Apache Default Index File - php

I want apache2 to host home.php or whatever I choose as the start page instead of index.html. Everything I have read says to edit the DirectoryIndex parameter of the httpd.conf file. I do not have that file anywhere. (I searched.)
I also did not have an .htaccess file by default. I created one and put the line DirectoryIndex home.php in it; I then restarted apache. Nothing chaged.
This is in my apache2.conf file.
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
I am not sure what Options Indexes FollowSymLinks does.
These are the file contents of my /var/www/html/.htaccess.
<Directory /var/www/html>
DirectoryIndex home.php
</Directory>
When I change AllowOverride to All I receive a server error.
Thanks.

The best way is to add DirectoryIndex to your vhost configuration.
<Directory /foo>
DirectoryIndex home.php
Allow Override All
</Directory>
When you want to use that option ins your .htaccess file you have to set AllowOverride All in your vhost configuration. Otherwise you should get an error in your log DirectoryIndex not allowed here.

Related

enable htaccess apcahe on ubuntu

I have an apache server on ubuntu where i have a virtual host that points to my site. Problem is my htaccess not functional.
In my apache2.conf file i have something like
<Directory />
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
if i change AllowOverride for "www" directory htaccess is functional but i get 403 forbidden error. please guide me what i am doing wrong.
regards.
You have to set AllowOverride to all like this.
<Directory "/var/www">
AllowOverride All
</Directory>
After that if you are facing forbidden error then probably you have error in htaccess file. Remove the code in htaccess file then start writing code block by block. By this you can debug error in htaccess file. For more info, you can have a look on this.
https://askubuntu.com/questions/429869/is-this-a-correct-way-to-enable-htaccess-in-apache-2-4-7-on-ubuntu-12-04#answer-429931

Configuring a RESTful VirtualHost on Apache 2.4 with PHP

I'm trying to create a RESTful API on a VirtualHost on my Apache 2.4 server (on Ubuntu). I have a php file named dbManager.php which I am using a RewriteRule to look like an api directory. It's working great except for PUT and DELETE commands, which are returning 403 errors. Here's a redacted version of my conf file:
<VirtualHost *>
ServerAdmin onigame#gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
<Limit PUT DELETE>
Require all granted
</Limit>
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Well, the PUT and DELETE still aren't working and returning 403. I'm also worried that I don't really want to allow PUT and DELETE everywhere on the directory, but only through the dummy api directory. What's the right way to do this?
I have managed to solve my question, but I don't really understand why it works:
<VirtualHost *>
ServerAdmin onigame#gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /path/to/local/dir/>
Require all granted
Satisfy All
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Best I can figure out, getting a 403 means that it's access being blocked, and not the type of HTTP request (which would result in a 405, not a 403). And the access problem is on the local directory, so it needs a special section for it. But I really don't understand why the two lines I put there make things work. The Require directive, that sort of makes sense. But the Satisfy directive, from what I can tell from the documentation, should default to All.
And yet when I remove either line, it doesn't work.

Htaccess ignored on live server

I'm using a .htaccess file to use clean url's, Everything is working fine on my localhost, but on the production server my .htaccess is ignored..
I have an index.php entry point which requires the files needed.. But as you can see when you browse to
http://mindstretchscan.eu/overzicht , it's trying to load the required page directly. but not the index.php.
http://mindstretchscan.eu?page=overzicht is working! and it's the same page..
This is the top of my .htaccess
<ifModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine on
Any idea what I might be doing wrong? Pulling my hairs out on this one. Thanks!
Make sure mod_rewrite is enabled
#sudo a2enmod rewrite
#/etc/init.d/apache2 restart
You also need to enable the use of .htaccess files by changing AllowOverride None to AllowOverride FileInfo. For the default website, edit /etc/apache2/sites-available/default
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
And make sure you restart apache again.

How can I add an alias to Apache in XAMPP v3.2.1?

I have added an alias in the httpd.conf file to access my folder at localhost/projects :
<IfModule alias_module>
Alias /projects "C:/Users/Ben/Google Drive/Projects"
<Directory "C:/Users/Ben/Google Drive/Projects">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ScriptAlias /cgi-bin/ "C:/xampp/cgi-bin/"
</IfModule>
When I try to start Apache in XAMPP 3.2.1 nothing is written to the error.log and Apache fails to start.
File:
httpd.conf (original)
After of:
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
Put:
<Directory "C:/Users/Ben/Google Drive/Projects">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Alias /projects "C:/Users/Ben/Google Drive/Projects"

htaccess doesnt work in virtual hosts but yes in default site

Im having some issues with the virtual hosts apache files and htaccess.
I have apache, updated to 2.6 yesterday. I installed 2 virtual domains on it, and disabled the default domain.
All works fine, sites loads fine, no problems there.
The first virtual domain has a htaccess with +50 rewrite conditions and all them work fine!
I tried to add some conditions to the 2nd domain, but the ones that rewrite directories dont work.
This is the condition:
RewriteRule ^user/([a-zA-Z0-9_-]+)$ index.php?username=$1
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ index.php?username=$1
And there, the "sites-available" apache config files for each domain (only the relevant things):
DOMAIN 1:
ServerAdmin webmaster#localhost
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/domain1.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
<Directory /var/www/domain1.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
DOMAIN2:
ServerAdmin webmaster#localhost
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/domain2.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
<Directory /var/www/domain2.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
As you can see, there is no diference between them other than the path to main folder.
I dont understand whats wrong with it.
Why the first domain works perfect and the second one no.
Some things:
A: Any other condition on the domain2 htaccess file works just fine, like redirec simply html to php, or errorhandlers, or just simply redirects to test.
B: I pasted the same rewrite condition in my first domain htaccess file, and it works perfect!
It looks like the apache config file is not working correctly.
Is there anything I must check/change?
I will appreciate any help, and sorry for my english.
Give this a try its tested and working:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^user/([a-z0-9_-]+)/?$ /index.php?username=$1 [NC,L]
I believe the issue is that you have MultiViews enabled, you can also resume your 2 rules into 1 like I have done above.
This should go into the .htaccess of your domain2.
As a side note, you do not need 2 directories directives, you can remove this one:
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
And keep just:
<Directory "/var/www/domain2.com/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>

Categories