1
votes

I have removed index.php from a url using following code but if i type ww.mywebsite.com/index.php then with this url also it is working but i want to remove index.php if user types index.php in between the url. This is my code of .htaccess file

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]
    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
</IfModule>
2

2 Answers

0
votes

For .htaccess you can try this -

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]  // path to your public directory
</IfModule>

or

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(.*)index\.php\sHTTP.*$
  RewriteRule ^ /%1 [R=301,L]
</IfModule>

Hop one of them will work.

0
votes

Options -MultiViews -Indexes

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]

Option 1 Point public folder directly in host file

<Project Path>/public

Option 2

  1. created 1 folder protected in project root
  2. all folder and file move to protected folder except public
  3. all public folder & files move to root folder
  4. and change include path in public/index.php

    require __DIR__.'/../vendor/autoload.php'; require_once __DIR__.'/../bootstrap/app.php';

to

require __DIR__.'/protected/vendor/autoload.php';
require_once __DIR__.'/protected/bootstrap/app.php';