0

I've a laravel 5.4 over apache centos server.

the folder structure are like: /var/www/html <- public folder /var/www/project <- laravel project folder /var/www/html contains the "public's laravel folder" content like css/ js/ and index.php etc.

index.php contains references to the project main folder. the project works but just with ip like:

myip/index.php/login

and not

myip/login

as I would like I try many way to remove it but without luck, this is my .htaccess file inside /var/www/html:

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

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

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ index.php/$1 [L]


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

JahStation
  • 893
  • 3
  • 15
  • 35

3 Answers3

1

Instead of changing the .htaccess file, you should change the server configuration to serve files from Laravel public folder.

Before editing the config file and to be safe, copy the default config file to have a backup: cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.original

Edit the file /etc/httpd/conf/httpd.conf as the follwoing:

change this line:

DocumentRoot "/var/www/html" 

to

DocumentRoot "/var/www/project/public"

Add the follwing lines to allow serving files from Laravel public folder:

<Directory "/var/www/project/public">
    AllowOverride All
    Require all granted
</Directory>

Run sudo apachectl configtest to make sure you did not make any mistake. You should get Syntax OK.

Restart the apache server to apply the new configuration. sudo systemctl restart httpd

Finally, restore the .htaccess file to the default version that comes with laravel at this link.

It's better to create a virtual host instead of changing the default configuration. However, this will be ok if you have only on website on the server.

Hamoud
  • 1,909
  • 9
  • 13
1

You need to go on the laravel documentation deployement/apache and you will see the rewriter rules you need to put them rules in your apache configuration. And all will work

Jud3v
  • 191
  • 3
  • 14
0

For those who work with laravel 7.x: MAke sure have .htaccess in both public and root folder of your project with bellow content

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

By the way, don't forget to set AllowOverride to All in /etc/httpd/conf/httpd.conf (on CentOS):

<Directory "/var/www/path/to/my/app/public">
    Options FollowSymLinks
    AllowOverride All
</Directory>

Goodluck.

vahid sabet
  • 485
  • 1
  • 6
  • 16
  • Hello you need to go on laravel documentation for deployment and Apache section you will see the rewriter because apache does not support rewrite rules – Jud3v Jul 11 '20 at 17:07