I would like to know if it's possible to point my domain to a directory which is two folders in from the root.
My hosting company doesn't allow me to change this so I need to do this with an .htaccess file.
This is my structure...
public_html
.htaccess <-- Here will be my .htaccess file.
folder
folder
folder
folder
public <-- My desired folder.
All requests must point to the public folder 2 levels downwhere the frameworks .htaccess file exists and index.php file exists.
I hope this all makes sense.
Thanks.
Use RewriteBase
RewriteEngine On
RewriteBase /folder/public/
RewriteRule . /folder/public/index.php [L]
Related
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 a question (and really tried already a lot of things).
this is the folder structure on my root:
.htaccess (root)
/2014
/2015
/2016
/2017
.htaccess (2017->laravel redirect)
public
index.php
css
where 2017 has a Laravel website.
I know I need an .htaccess file inside the 2017 folder to rewrite to the public folder where the index.php file is /public
This is the .htaccess file in the 2017 folder to achieve this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
First problem I have here is that now inside my Laravel code, when I access the website via www.dotfmp.com/2017 the $REQUEST_URI contains now "2017/{page}" instead of only "{page}".
My second question is what should be my .htaccess file in the root, so that any request coming on the www.dotfmp.com website will go to /2017 folder, however www.dotfmp.com/{folder} should go to the intended folder.
An answer would be nice, an explanation even better, and a good resource the best :)
Thanks in advance
Andries
I have directory in my website where user can upload projects or create sub directories, in the root dir i have a default .htaccess file and default.php which i don't want the user to get access to because i rewrite the dir to load default.php as default index page and also this to file will be copied to any sub dir that the user create.
Now my problem is when user try to save .htaccess for the project he want to save it will show that is already exist. is there anything i can do to have multiple htaccess or write my own as default htaccess.
Second. is it possible to use one htaccess in all the sub dir so user can freely add their own?
Example: bellow is how my directory look
WWW.example.com/ project /userprojectname/sub1/sub2/sub3/etc...
In project it has htaccess and users are not allow to do anything but their projectname will save there.
In userprojectname it has an htaccess and default.php, they can also add more file or create directories and any sub dir will also have it own htaccess and default.php.
Now can i make htaccess in project work in all page? and as for default, i used jquery to disallow users creating file name default.php also is there a better way i can fix all this?
Bellow is my dirs and htacess file
Options +FollowSymlinks
RewriteEngine on
#This will block from accessing root folder
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)$ $1.php [NC,L]
DirectoryIndex default.php
I have the following directory structure:
root
folder1
foldera
file.php
folder2
folderb
index.php
.htaccess
I would like to route all requests to index.php and have this apply to all folders. Here is my .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
This seems to work fine for localhost/root. The request is correctly routed to index.php. But for localhost/root/folder1 or localhost/root/folder1/foldera/filephp it does not work. Is there an additional rule I need to define for this to work?
From: https://httpd.apache.org/docs/current/howto/htaccess.html
The configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up,
or in the main server configuration file itself.
If your htaccess is in the root, why the '../'? As it stands it is redirecting to an index.php above your root directory.
If you want it to work for all requests, remove the two rewrite conditions. Right now it is saying: "rewrite request only if the request is not for a file or a directory that exists".
If you don't want files in other folders to be directly accessible, it probably makes sense to move them outside of the web root entirely. So your front controller would be in a web/ subdirectory, and the webserver's docroot would point at that instead.
root
folder1
foldera
file.php
folder2
folderb
web <- DocumentRoot should point here
.htaccess
index.php
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