I am using a laravel app my domain is showing pages like: www.mysite.com/public/about
on every page there is a duplicate page with /public/page_route , how could I fix this from .htaccess file.
My .htaccess file code:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ www.mysite.com/$1 [NC,L,R=301]
# 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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<Files ~ ".(env|json|config.js|md|gitignore|gitattributes|lock|editorconfig|yml|styleci.yml)$">
Order allow,deny
Deny from all
</Files>
Options -Indexes
<Files ~ "(artisan|package.json|webpack.mix.js)$">
Order allow,deny
Deny from all
</Files>
I am trying to make all routes should be open without public name in route like:
2
Answers
Please make index.php file in root
=================
also make .htaccess file in root
after this try accessing route without public
Domain’s document root
The domain name should point to the /public folder as if it were your "public_html" folder.
Whenever a request is made to this domain, the index.php should be executed
You need to place an
.htaccess
file in the/public
folder that contains the lines you mentioned, especially these:Return the appropriate content due to Laravel routing
This way, every URL called under a domain name will start from your
/public/index.php
, which builds up your Laravel app. Eventually, it will either run the appropriate route defined in the/routes
or return a 404 blank page if no matching route is found.Conclusion
The
/public
appears in the URL if your domain name points to your-project instead ofyour-project/public
. Therefore, you can access your startingindex.php
withhttps://example.com/public/index.php
.If the root of your domain points to the
/your-project/public
folder and you can still access its content using the/public
address, then either you have incorrectly set up the Route in the/routes/web.php
file (perhaps created a group named "public" or added the/public
URL part to every route), or your domain is pointing to the/your-project
folder incorrectly.