简体   繁体   中英

PHP framework and shared hosting with ftp inside only the public_html

lately I'm trying to learn php frameworks, cause I want to implement them in my projects, implement routes and secure sessions/form handling and I'm sick of using wordpress for client's works, so I discovered Slim, and I made the example app that you can find in the project's homepage.

Now, for various reasons, I know a lot of client will end up opting for a shared hosting solution, when it's just a showcase website, so I made some research about shared hosting configuration and .htaccess file. I used altervista to make a test and see if it works (it's a free hosting service, shared), the only problem is that every tutorial I followed, assumed that when connecting through ftp you can see the doc root (public_html, htdocs and so on) but still upload out of it, instead, in this case I can only see the inside of public folder.

This had me a little bit confused, but I tried anyway, I uploaded all slim files (including public app folder and all necessary background files), made an .htaccess, and uploaded it, that's its content :

RewriteEngine on
RewriteCond %{HTTP_HOST} ^minimaleffort.altervista.org$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.minimaleffort.altervista.org$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

I went to the index of my website and the home screen of slim framework appears as intended (a bit edited cause I implemented bootstrap css)

在此处输入图片说明

Everything works, right? No, wrong, if I type a route (for example the default app route)

/{name}

It returns a 404 error page, while it should print on screen whatever name I put in the URL, am I missing something? If you wanna check the site directly here's the url

If you check the official Slim 3 example application , its .htaccess file reads as following:

RewriteRule ^ index.php [QSA,L]

I am by no means a mod_rewrite guru, but I think you are not passing the query string to the index file. This is why the frontpage works, but not the other pages.

I think your .htaccess file should look something like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^minimaleffort.altervista.org$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.minimaleffort.altervista.org$
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(.*)$ /public/index.php [QSA,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM