0

In my url http://example.com/public/index.php in my laravel website. i want to remove only public remember not index.php i want to see my url like http://example.com/index.php

public .htaccess

<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]
</IfModule>
Mizanur Rahman
  • 83
  • 1
  • 14
  • 1
    Possible duplicate of [Laravel 5 – Remove Public from URL](https://stackoverflow.com/questions/28364496/laravel-5-remove-public-from-url) – Dilip Hirapara Oct 17 '19 at 06:53
  • no. there remove both public/index.php. but i want to remove only public not index.php. remember not index.php – Mizanur Rahman Oct 17 '19 at 06:55
  • When I made one of my demo projects live, I just pointed my subdomain till the public folder path. So, now `public` isn't present in the URL and everything runs perfectly. Don't see why people deal so much with .htaccess here. – nice_dev Oct 17 '19 at 07:11

2 Answers2

0

You can use rewritebase, if you want to only remove public and not index

# invoke rewrite engine
    RewriteEngine On
    RewriteBase /~app-folder-name/

# add trailing slash if missing
    rewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L]

if You want to remove public/index, set document root in your apache2 config.

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
0

Copy .htaccess file from public folder to the root folder and replace the code with the below code.

<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 ^ server.php

try the code and let me know.

Jithesh Jose
  • 1,781
  • 1
  • 6
  • 17