Here is my Directory Structure
localhost/project or livehost/project
-app
-bootstrap
-public
-vendor
Where i have /project as a folder inside the htdocs.
Now i am accessing the project by
localhost/project/public/
localhost/project/public/blog // for submenu
How can i remove the /project/public/ and use only the localhost/project and localhost/project/blog
And if move to live i will be having the project folder as main so How can i have the .htaccess for the localhost (which is inside the project folder) and live (which will be in the root)
Here is the .htaccess i had for the the live (where the files will be on the live)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder. -- Thats it !! :)
First you have to make sure mod_rewrite is enabled on your server (you can go here if you don't know how to do). If it's already enabled but URL rewrite seems to not work, you can refer to "pretty URL" chapter of Laravel's documentation : http://laravel.com/docs/4.2/installation#pretty-urls
Related
Laravel Version - 5.8.
I have to deploy my Laravel project on Shared Hosting without using php artisan serve command. So for that reason, I have renamed my root file server.php file to index.php.
Will there be any security consequences or bug, if I rename the file server.php to index.php?
you don't need to rename server.php to index.php. Just move the Public/index.php to the root of the folder and change the necessary path inside the index.php after moving. It will work for sure.
If you using cPanel, you can change webroot to public very simple don't need to rename server.php. If not you can using .htaccess to redirect all request to public folder like this :
# public_html/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect All Requests To The Subfolder
RewriteRule ^ /public
</IfModule>
I'm using Laravel 5.3 is there a easy way to remove public from URL? is it necessary to add a htacces. when I change the htacces it is getting a n error like below,
copy both htaccess and index.php file from public folder to root directory and then change root index.php code as below
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
https://laravel.com/docs/5.3/installation#configuration
Do not edit .htaccess or Laravel related files, just point web server to a public directory instead of Laravel project directory:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
Then restart Apache.
Add a .htaccess file in root which contains -
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Yes it is very simple no need to add extra htaccess,
Create a new folder in your laravel project folder.
Name it whatever you like. Example :- source
Move all the files from root into 'source' folder except 'public' folder.
4 . Move all the files from public folder to root.
5 . Change the autoload.php path
6 . Thats all. remove public folder if necessary.
In the root directory create a .htaccess file and put the following in
it
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Even above solution(s) work(s) for you,but I would recommend not to do this.
Here is the reason why.
-You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
-you have to configure apache for user not access .env, git files , config folder's file
public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition.
Copy all files and folder from public folder to root folder and edit your .htaccess file as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And dont forget to change the paths in index.php file.
For details refere following links
Installing Laravel in a subfolder
https://ellislab.com/forums/archive/viewthread/151342/#734511
I have my site already built up in say: http://example.com
My Directory structure is:
root/
|
-- htdocs/ ---> This is the document root. All the front end scripts are located here.
| |
| - css/
| - ...
|
-- cms/ --> This is the backend. This site is like a cms Driven Site.
Now I wanted to install laravel in the back end. I want to build my CMS using laravel. But I don't want the URL to be like: http://example.com/cms/public/
I want it just to be: http://example.com/cms/
I know, I can just place all the folders outside in the document root and rename the public folder and change some settings to achieve what I want. But I don't want my document root to have all those files & folders and files mixed with my front end related files & folders. I want this whole thing to be separate and easy to use in other web site back end.
In order to achieve this, I have used 2 .htaccess files.
In the document root, I have:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^cms/$ cms/public/ [L]
RewriteRule ^cms/(.*)$ cms/public/$1 [L]
</IfModule>
And inside the cms folder I have:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I am not very good at writing .htaccess or doing mod_rewrite.
Can anybody help me
You could achieve what you want in this way:
Create a directory junction for the public folder from laravel to your backend target folder:
mklink /J C:\www\htdocs\app-frontend\cms C:\www\htdocs\app-backend\public
The first path is for the alias and the second path is for the real folder. Here app-backend would be the folder where laravel is installed to.
This is how I deal with Laravel in shared hosting.
If you were to opt for the mod_rewrite approach, the .env file will be exposed.
I have a Codeigniter install with a directory 'sandbox' at root. In sandbox i have document 'poster.html'. If i change this document's extension to .php, I get a CI 404 error. If i leave it as .html it works!
Edit: I just confirmed that .php extension does not work from any of the excluded directories like: css/ or scripts/ .
Here is what the .htaccess file at the root directory looks like:
RewriteEngine on
RewriteCond $1 !^(index\.php|sandbox|css|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Current root directory structure:
application/
system/
css/
sandbox/
scripts/
.htaccess
index.php
I believe your issue is either you have a typo somewhere, or you have a ROUTE conflict.
I just recreated this with a new 2.1.4 CI install and created a sandbox folder with a php file in it.
I can confirm it is working 100%. Double check your spelling. You shouldn't be getting a CI 404 page for the /sandbox/ folder based on your .htaccess
As an alternate debug approach, turn up your ci logging and check the /application/logs for detail on what is it throwing a 404 on.
I'm trying to make a simple Zend Webapp running on a shared host. The root folder after logging on FTP server is a folder named 'www'. So the structure is:
/www
/tasklist
/application
/library
/public
/.htaccess
Hosting provider demands to have all paths in .htacccess file absolute. Considering this, the path to main index.php of my Zend app is:
http://aportsupport.cz/tasklist/public/index.php
Which is also a link at which I am able to access my app but with other paths to certain files (css, js etc.) do not work. When I try to access my app with:
http://aportsupport.cz/tasklist/
I only get 404 or 403 error depending on various setups of .htaccess I've already tried.
I have no access to error log, nor any server configs. Default controller is 'index', action 'index', module 'default'.
In a Zend application, the .htaccess should be in your public folder, so your folder tree will look like this:
/www
/tasklist
/application
/library
/public
/.htaccess
Your .htaccess can be kept simple for most Zend applications. Try this text out for .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteBase /
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
What this breaks down to is that no matter what url is requested from this root directory, it will try to fetch the file /www/tasklist/public/index.php, which will bootstrap the Zend application.
Remember that if your hosting provider does not support Zend Framework, it may not work out at all. Hosting providers like http://www.phpcloud.com/ do allow Zend-based applications but you have to specify it on container creation.
Thank you for your response, however, I've finally managed to make it work myself. For all those who might have similar issues this solution worked for me:
I created a subdomain 'tasklist.aportsupport.cz' which has its own root folder on my shared host. In this folder I put all Zend folders with their default structure. Also I created index.php file in which I wrote this:
<?php include 'public/index.php';
This index.php is located in root of tasklist.aportsupport.cz with default Zend Framewrok .htaccess in which I added this line:
RewriteBase /
Also all CSS, JS, imgs etc. files are located in that root folder. Everything works just fine!