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.
Related
I am programming a php model-view-controller.
Basic structure:
mvc
|
|app
| |_ models
| |_ views
| |_ controllers
|
|web
|_index.php
|_css
|_js
...
As so I use my .htaccess file for redirecting the url:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mvc/web/
# Let any content of web be shown (css, fonts, images, js)
RewriteRule ^web - [L]
# Lets .css or .js files from other folder through (for app/views/[...]/(css|js)/ )
RewriteCond %{REQUEST_URI} !^.*\.(css|js)$ [NC]
# Rewrites everything else to web/index.php
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Because I'm implementing a bash-script editor (ACE) and I would like a linter, I am trying to get shellcheck (https://www.shellcheck.net/) running to do the same thing as in the demo.
Now when I put all needed files in the /web folder and access them directly via localhost/mvc/web/codeeditor.php the linting works so i figured out it must be something with the redirection in .htaccess
shellcheck comes with a css and a js file, a js library (all of those get loaded), a php file (Content-type: application/json) and an sh file (ajax request -> php -> executes sh -> returns json) and then there's ofcourse my codeeditor.php (set up correctly because it works in the other directory).
Which of these files or what else could be the reason that the redirection isn't working as I'd like it to :P?
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
I have an root folder like this:
ROOT
|- Service
| |- Admin
|
|- Service 2
I'm interesting in accessing the admin folder from service folder
To access the admin path via url i use mydomain.com/Service/Admin
Is there any way to make it access like this mydomain.com/Admin without moving folders?
I got the answer from one guy and is working, but is not working if i don't add / at the end of Admin
RewriteEngine On
RewriteRule ^(Admin/.*)$ Service/$1 [L,NC]
mydomain.com/Admin/ - working
mydomain.com/Admin - not working (404 error)
I want both to work
I made is like this and is working
RewriteEngine On
RewriteRule ^Admin$ http://mydomain.com/Admin/ [L,NC]
RewriteRule ^(Admin/.*)$ Service/$1 [L,NC]
I am sorry about this, but my htdocs root is wrong and I can't change that. So I have to make it work in the /public folder.
I use the normal Laravel .htaccess file with the following rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If I open http://kemtime2_neu.pr.domain.de/public I get redirected to http://kemtime2_neu.pr.domain.de/public/http://kemtime2_neu.pr.domain.de/public/login
How can I fix this?
I would love to make it work from http://kemtime2_neu.pr.domain.de/ but getting it to work with http://kemtime2_neu.pr.domain.de/public/ would be fine.
I use the 3 solution of this post and works fine:
http://web.archive.org/web/20130320184846/http://forums.laravel.io/viewtopic.php?id=1258
Solution 1 - Alternate installation path with symlink.
This is the preferred solution and in general an all-around good idea. It's possible to install your application to a folder unrelated to public_html/ and then symlink the public folder to the public_html/ path.
For example:
Install your application to /home/applications/mysite.com
Imagine that your DocumentRoot points to /var/www/vhosts/mysite.com/httpdocs
Remove the httpdocs folder from the mysite.com vhosts folder then connect the two with a symlink: ln -s /home/applications/mysite.com/public /var/www/vhosts/mysite.com/httpdocs
Solution 2 - .htaccess with mod_rewrite
This solution enables you to drop Laravel into your public folder then use a .htaccess file to redirect requests to the public folder. This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Step 1. Place Laravel in your document root folder.
Step 2. Place the following .htaccess file in your document root folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Step 3. Make sure that you manually set your 'url' configuration in application/config/application.php otherwise Laravel will generate incorrect URLs. Make sure that each of your environments have the correct application.url configuration. For more information on environment-specific configurations see: http://laravel.com/docs/install#environments
Solution 3 - merge the public folder into the installation root
This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Copy the contents of the public/ folder into your Laravel installation folder then change this line in your index.php file from:
require '../paths.php';
to
require 'paths.php';
Keep in mind that any bundles, libraries, or other types of third-party code may not be designed to be publicly accessible.
Note: It's also important to note that your bundles/ and public/bundles/ directories will now conflict. When using this approach you may want to not use artisan's bundle:publish task without knowing exactly what your bundles want to publish.
I solved it partly. If I have a .htaccess in the root instead of /public with
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/index.php/$1 [L]
I can open http://kemtime2_neu.pr.domain.de/login but the images and css is still wrong. I need to check first if the files exist in /public. I think this is a new question.
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!