0

I have two websites on a Red Hat Linux server; the first one is located in var/www and has the below configuration on var/www/html/.htaccess.

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
  RewriteEngine On

 # Reroute to index.php
  RewriteCond $1 !^(index\.php)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php [L,QSA]

</IfModule>

The second site is located in var/www/laravel, and its config file is in var/www/laravel/public/.htaccess. I have tried using the same config as the first site, deleting the file, and using default config listed below:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I have also used the config provided in the documentation:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I have also checked if my mod_rewrite is uncommented with this command:

grep -i LoadModule /etc/httpd/conf/httpd.conf | grep rewrite

and it is.

The first website works fine without index.php, but the Laravel one needs it. Any hints on what I'm doing wrong?

EDIT: thats how I created the alias for the second website maybe it helps:

<VirtualHost *:80>
   ServerAdmin example@example.com
   DocumentRoot /var/www/html/
   ServerName www.example.com
   ServerAlias *.example.com
   Alias /laravel /var/www/laravel/public/
   ErrorLog "|/usr/sbin/rotatelogs /var/log/httpd/www.example.com-error_log.%y%m%d 86400"
   CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/www.example.com-access_log.%y%m%d 86400" combined

#   php_admin_value upload_tmp_dir "/var/www/html/tmp/"
#   php_admin_value open_basedir "/var/www/html/:/var/cache/www/"

   <Directory /var/www/html/>
      AllowOverride All
   </Directory>

   <Directory /var/www/laravel/public/>
      AllowOverride All
   </Directory>
</VirtualHost>
Cristian
  • 342
  • 4
  • 17
  • Can you show your apache's virtual host file? – Wouter Van Damme May 20 '19 at 13:59
  • edited my question maybe it helps – Cristian May 20 '19 at 14:33
  • If the vhost file listed is for your second site, you should probably change your `DocumentRoot` setting to the folder that your second site is in. – Das_Geek May 20 '19 at 14:38
  • I only have one vhost for both, i'm using an alias to point where is the second website inside the first one, should i create a new vhost? – Cristian May 20 '19 at 14:43
  • No, that's fine. See the edit to my answer below: try adding the `DirectoryIndex index.php` line to the `` tag for your second site in its `httpd.conf` file. – Das_Geek May 20 '19 at 14:46
  • added it there, tested in both sites, still need to put index.php to enter in the second website, i dont know what's going on – Cristian May 20 '19 at 14:52

1 Answers1

1

The simplest solution is covered in this answer. Assuming your Apache server is configured to allow .htaccess files, edit the one that corresponds to your site to include the line below:

DirectoryIndex index.php

Per the Apache documentation,

The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory by specifying a / at the end of the directory name.

If your .htaccess file does not already have index.php listed for the DirectoryIndex directive, you will need to add it to let Apache know it can serve that file when the base address is requested by your browser.

If you do not want to configure your server to allow .htaccess files, you may change the httpd.conf file for your site instead:

<Directory /path/to/site/>
    DirectoryIndex index.php
</Directory>
Das_Geek
  • 2,775
  • 7
  • 20
  • 26