juliereader's avatar

301 redirect to non /public/index.php url

Hi there, I have laravel based website and if you visit it, it shows you clean urls as follows

domain.com/site/myfoldername

however the same page can be also accessed via the following url

domain.com/public/index.php/site/myfoldernname

I need to 301 redirect

domain.com/public/index.php/site/myfoldernname

to

domainl.com/site/myfoldername

my current htaccess in root (public_html)

#AddHandler application/x-httpd-php55 .php
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

my current htaccess in laravel public folder

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
<FilesMatch "^.*?style.*?$">
SetHandler php5-script
</FilesMatch>
0 likes
11 replies
Snapey's avatar

you really need to change the web server to have public as the root folder and not try to work around it.

my betting is also that domain.com/.env will reveal some interesting information

thefuzzy0ne's avatar

+1

Each app should reside in it's own directory. You shouldn't have one app inside of another. That's Appception!

juliereader's avatar

i am not a programmer or developer so I do not really want to move anything that break my app. It tool me almost 1 month to finally make it run smoothly and it has lots of data now. So any url redirect via htaccess is my first preference

Snapey's avatar

But listen. You could have a big security hole if you are using values in .env and are exposing this folder to the world.

1 like
jlrdw's avatar

You could practice moving it properly in your development environment and then when you have it all working properly you will know exactly what to do in your production environment. And listen to @Snapey advice he is 100% correct on that. If nothing else temporarily hard code the configs.

Edit, also see this page and look at @Qlic answer https://laracasts.com/discuss/channels/laravel/upload-project-laravel In fact I used that technique when putting a site on Godaddy.

juliereader's avatar
  1. I am running my site on a VPS
  2. There is no ENV file in any public folder.
  3. It took me lots of time and efforts to make this thing run correctly so I really dont want to move anything that may break the site. Isnt there any htacess 301 rule that i can use for just the urls :)
bashy's avatar

I have no idea about Apache, sorry.

juliereader's avatar

have figured it out finally. Thanks for all the replies.

Please or to participate in this conversation.