I'm trying to upload my ZF Project to shared hosting
On my XAMPP, ZF's index page is located (and I access my page) at http://localhost/ZFprojectname/public
On the shared hosting in the root directory I have installed Joomla.
I want to access my ZF in the manner of http://mywebsite.com/booking/
so in this case, when going to http://mywebsite.com/booking/ I should be accessing ZF's public folder (as far as I understand).
And, I'd like to put my ZFproject in public_html/somefolderName/
How would you do it?
Shared hosting do not support defining Document Root path so you can use .htaccess to forward the request to public folder instead.
Create a .htaccess file inside the booking directory with the following rule.
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
Related
My question is: How can i run a laravel application in a directory
(not in root) on a shared webhosting?
For some of my clients I run Laravel applications in the root folder of their selected shared webhosting and remove the /public part from the URL. To make this work i move the index.php to the root folder and change the information from the index.php to:
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
Now i know that this can cause security problems but I already have found solutions to that case for shared webhosters.
The .htaccess i use to make this change is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.eot|\.woff|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1/$2 [L,NC]
But in this case i want the laravel project to be run in a directory called test.
Folder structure:
root (public_html)
|-- test (directory with laravel project)
Now I'm not sure if i can simply change the .htaccess as i'm not very skilled with .htaccess files. What changes do i have to make, to make this work?
Note my urls:
// this link will be changed to:
www.[text-placeholder].com/test/public/css/style.css
// Output above result now:
www.[text-placeholder].com/public/css/style.css
// But should be:
www.[text-placeholder].com/test/public/css/style.css
It's easy, just place the project 1 level above the public_html folder and rename the public folder itself to public_html.
P.S. This is maybe a better way, than to use .htaccess, because now you really know fore sure the files outside of public html are out of your webroot (not accessible by hackers) and with htaccess you can make a mistake and the files are exposed.
I have a c-panel shared hosting. Now, the docroot for the sitename.com resides at public_html folder. Say, I have a symfony application installed in the same. So, the web folder for my symfony application is at public_html/symfony/web/. If I want to try it, I should hit sitename.com/symfony/web/app_dev.php.
Here's the tricky part: I am trying to use htaccess somehow to get sitename.com/hi to invoke sitename.com/symfony/web/app_dev.php/hi internally. The constraints are, I cannot modify my httpd-vhosts.conf to update my hosting directory. It might not be a practical thought, still, would love to figure out this, just as some food for thoughts.
try this in your public_html
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L]
Edit .htaccess in public_html folder and add rewrite directives to pointing your request to wanted foder /symfony/web/ :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sitename.com$ [NC,OR]
RewriteCond %{REQUEST_URI} !symfony/web/
RewriteRule (.*) /symfony/web/$1 [L]
DirectoryIndex app.php
If you are using /symfony/web/app.php as front controller don't forget to add directive DirectoryIndex.
I completed my project on ZF2, then uploaded it on shared hosting. I would like a folder for the zend app with all the files inside, and then in the document root I would like the files from the public folder to be visible, because I want my URIs to look like www.example.com (not www.example.com/public/).
What I have done in those cases with ZF1 app is to throw an app directory in the document root and with your server's .htaccess equivalent made it not serve files from there (Deny from all). Then stick your gateway script into the document root and update the paths found in there including APPLICATION_ROOT and the path to the autoloader.
Hope this helps.
You can move the files inside /public to your webroot. However, please be aware that config files below your webroot are a security risk.
This one work.
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
My zendFramework application on server shows
xyz.com/public/login
i want it like
xyz.com/login
how to achieve this ? is it possible to do with .htaccess file?
This is my answer from another question, but seems to fit in this question too. In the case you already have a .htaccess file inside public, use the htaccess solution from below.
The problem seems to be due to the root not being routed to /public.
The proper way: You need to setup a vhost and point the root to the public directory.
Another Way: You need to redirect every request inside public directory. The .htaccess for this file would be
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
You have to create a virtual server Zend have a tutorial to do so.
If you are not able to create virtual server by any reason. You can put the public index.php file outside the public folder. If you choose this method you have to add extra security methods, choosing this method lead to direct access of files.
You can prevent those direct access by creating .htaccess in those directories with these lines-
<Files *>
Deny from all
</Files>
Let's say we have the following schema:
root/
application/
-public/
index.php
css/
img/
javascript/
...
system/
...
I was thinking that if I create an .htaccess file in the root with the following rules:
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application/public/index.php?url=$1 [QSA,L]
I would be able to make other folder except public unable to be accessed. Assume index.php is the file that load all the file the application need and include and require them (with relative paths obliviously): the application is actually run in index.php and every public file such as css stylesheet, images or javascript script are in the public folder. So you, as user, cannot access the system folder because if you digit www.site.com/ it refers to root/application/public/. Am I right?
But the htaccess rule I set there does not work... If I put that htaccess in the root folder and I try to access the root folder the browser shows me the list of the file of the root folder (application and system). Why isn't it working?
I used this while ago when index.php was in the root folder:
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
and it worked just fine. Why isn't the new one working?
The document root of you project should be set to the /public folder.
This way that's the only folder to web-user would have access to.
Edit: for more info check the apache manual http://httpd.apache.org/docs/2.0/mod/core.html#documentroot
My initial code was right. Except for the third line which obliviously considered / a folder and made me see it instead of redirecting to application/public/.
Commenting the third line everything worked fine.
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application/public/index.php?url=$1 [QSA,L]