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}]

4
  • Possible duplicate of How can I remove "public/index.php" in the url generated laravel? Commented Nov 14, 2017 at 13:30
  • i found this post before but didnt work for me...and do not need even to cut the "public" part Commented Nov 14, 2017 at 13:31
  • How is DocumentRoot is set in the apache configuration? Commented Nov 14, 2017 at 13:40
  • is set to /var/www/html Commented Nov 14, 2017 at 13:53

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

looks so strange what happen right now, keep in mind that storage got "775" permission yet: ibb.co/frCXnb looks to the login part visible!
try chmod -R 775 storage
and I have no idea how is the login form coming out this way. so strange !!
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

Comments

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.