0

Normally the index.php in laravel framework is in the /public_html/public/ folder. In my case it is in /public_html folder

This is the code inside my .htaccess file

RewriteEngine On

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

# Handle Front Controller...

Options -MultiViews
RewriteEngine On

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

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

What changment should I make to exclude index.php from urls ?

The code structure is as follows :

/public_html/sitemap.xml

/public_html/sitemap.htm

/public_html/server.php

/public_html/robots.txt

/public_html/readme.md

/public_html/index.php

/public_html/.htaccess

/public_html/public

/public_html/database

/public_html/config

/public_html/cgi-bin

/public_html/bootstrap

/public_html/app


and inside /public_html/public


/public_html/public/web.config

/public_html/public/robots.txt

/public_html/public/favicon.ico

/public_html/public/upload

/public_html/public/js

/public_html/public/img

/public_html/public/css

  • http://stackoverflow.com/questions/37507209/how-to-hide-config-files-from-direct-access – Alexey Mezenin Jan 05 '17 at 06:50
  • not too versed in laravel (yet) but i believe in the app.config file you can set the base folder of your app which can avoid all the .htaccess hoops – happymacarts Jan 05 '17 at 06:52
  • if you will go into your home page you will see that you don't get it like `homepage.com/index.php`, but just the home page. you don't need to change anything. – GabMic Jan 05 '17 at 06:53
  • Hi there ! the problem is google has indexed some pages and the url it has saved in the search results is homepage.com/index.php/company/punjab-communications-complaints/4165 I need to fix this with the .htaccess. Any clue ? – ConfusedClown Jan 05 '17 at 07:28

3 Answers3

1

I highly discourage moving index.php out from the public folder. I was able to achieve what you are trying to do by following this tutorial.

There, you move your code base out from public_html folder to /appications/your-app folder and move content of public folder into public_html/your-app.

The tutorial is self-explanatory.

Gayan
  • 3,614
  • 1
  • 27
  • 34
1

I use this Laravel project's structure too (index.php in the project's folder). In my case I did next:

  1. rename server.php in the root folder to index.php
  2. Make .htaccess in the root folder:

Insert this code inside the IfModule mod_rewrite.c

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_URI} !(\.css|\.ttf|\.woff|\.woff2|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]

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

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

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|fonts)/(.*)$ public/$1/$2 [L,NC]
Paul Basenko
  • 895
  • 1
  • 9
  • 22
0

After spending hours I write below code for me and its 100% working.

Use this code just after

RewriteEngine On

Redirect index.php to non index.php

RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^index.php/(.*)$ /$1 [R=301,L]
Sandeep Yadav
  • 591
  • 1
  • 4
  • 14