hi, I want to change the root directory of my website which the server panel is CWP centos-web-panel. i find a solution that says change DocumentRootand directory in httpd.conf but I can't change that because a lot of my website using this server. I want to change the root folder in one of my websites.
also, I find another solution which said edit the file.
# nano /etc/httpd/conf.d/your_site.conf
and add this code to the file
<VirtualHost *:80>
DocumentRoot /var/www/html/your_site/public
ServerName your_domain
<Directory /var/www/html/your_site/>
AllowOverride All
</Directory>
</VirtualHost>
but not working.
how I can do that?
are any solution for that or with .htaccess or own laravel template?
so i want to change /public_html/ to /public_html/public/ in centos-web-panel
i using Nginx
Go to :
WebServer Settings -> Conf Editor -> Apache -> /usr/local/apache/conf.d/vhosts/
Search for mydomain.ssl.conf & mydomain.conf and click edit
Search for DocumentRoot and change it
From:
DocumentRoot /home/username/public_html
To:
DocumentRoot /home/username/public_html/public
Don't forget to restart Apache after that.
Done
Add this code in .htaccess
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
and copy index.php file to root folder and follow steps
https://hellocoding.wordpress.com/2014/05/17/how-to-remove-public-from-url-in-laravel/
https://hdtuto.com/article/laravel-remove-public-from-url-using-htaccess
You need to do the following thing to point your application without public in the URL:
Rename your server.php to index.php and copy your .htaccess file from public folder and paste it parallel to index.php (which is previously server.php)
And to hide your .env a file you need do add following lines in your .htaccess file
# Disable index view
Options -Indexes
# Hide a specific file
<Files .env>
Order allow,deny
Deny from all
</Files>
I prefer this answer. which is more secure. and no need to redirect.
create a folder in the public_html maybe foldername then move all of files and folders from the public_html to the foldername after that move all files and folders from public laravel folder to public_html open index.php and edit that like this.
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
to
require __DIR__.'/foldername/vendor/autoload.php';
$app = require_once __DIR__.'/foldername/bootstrap/app.php';
then hide .env file with .htaccess
Finish
if you have access ssh
remove public_html folder
rm -rf public_html/
create short cut to public folder (laravel) , we will put laravel in same level public_html
ln -s laravel/public public_html
now its done
I have created a new Laravel project (v5.5) which is related to my main website. Due to SEO-technical considerations I want the link to be like this: <mainwebsite.com/laravel>.
Both, <mainwebsite.com> and <mainwebsite.com/laravel> are deployed to an individual server. An Application Load Balancer redirects the traffic either to the main website or the new Laravel project.
The problem right now is that the Laravel app doesn't know that <mainwebsite.com/laravel> must be seen as the project's root. (The route / must go to <mainwebsite.com/laravel> and not to <mainwebsite.com>.
I've tried to add Route::prefix('laravel')->group() ... to web.php, which does fix the routes, but then the app's public dir can't be accessed.
Using relative paths like "/css/app.css" or "/laravel/css/app.css" won't fix this.
Is there a better way to set this up or does anyone know how this must be done?
The following did the trick for me.
Change the APP_URL in the .env file to http://www.mainwebsite.com/laravel
Move the contents of the public folder into a new folder inside the public folder and give it the same name as the path behind the URL (so in this case 'laravel').
/public
--- /laravel
------ /css
------ /js
------ index.php
------ ... etc...
Edit the relative paths in the index.php file:
require __DIR__.'/../../vendor/autoload.php'; &
require_once __DIR__.'/../../bootstrap/app.php'; (add an extra /../)
Set the right paths in webpack.mix.js and add the following rules to the beginning of the file to make sure relative paths in your files will be rewritten to the right dir:
mix.setPublicPath('public/laravel/');
mix.setResourceRoot('/laravel/');
That's it!
If you're using apache, setup .htaccess to rewrite the url:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/laravel/
RewriteRule ^(.*)$ /laravel/$1 [L,R=301]
</IfModule>
This should rewrite all url paths that do not start with laravel to ones that do.
For nginx, you could do the following:
location ^~ /laravel(.*) {
return 301 $scheme://$http_host/laravel$1$is_args$query_string;
}
I've gone through phalcon's documentation and followed the tutorial provided on the official site: https://docs.phalconphp.com/en/latest/reference/tutorial.html
The problem is when I browse the project (localhost/tutorial) it shows me the directory list as
app/
public/
What am I doing wrong?
The .htaccess file for the phalcon directory structure assumes you're working at the web root, not a subdirectory. You'd need to adjust your .htaccess file accordingly if you're not going to follow their proposed directory structure. The .htaccess file they give you is designed to redirect all traffic to the web root to your /public directory thus essentially hiding the /app directory from the web. Try placing their suggested web root .htaccess file in your tutorial directory and add a line RewriteBase /tutorial/. Then place their 2nd .htaccess file in your /tutorial/public directory adjusting its RewriteBase to RewriteBase /tutorial/public/.
Alternatively, you can avoid their public directory altogether and use a safer and faster directory structure, due to avoiding extra RewriteRules, albeit less convenient, by placing your app directory below the web root and adjust your PHP to use either dirname(__DIR__) or .. to refer to the parent directory when attempting to locate your app directory.
A final approach would be to create a subdomain on your localhost, http://tutorial.localhost/, yes localhost subdomains are a great solution for allowing web root access for multiple projects without stepping on each other's toes, then you'd edit your hosts file to add a record for the fake domain mapping it to 127.0.0.1, the same as localhost. Then edit your apache config file adding a virtual host for the subdomain mapping it to a specific directory to use as your web root for that subdomain, reload apache, and presto.
Thanks for the answers...but i figured out the problem myself.
The problem was the configuration setting in apache. I changed the setting in the http.conf in apache folder by removing the # from LoadModule rewrite_module. And that worked for me. cheers!
Steps:
Go to wamp/bin/apache/apacheVersion/conf
open httpd.conf
Uncomment or remove "#" from LoadModule rewrite_module
modules/mod_rewrite.so
So, I'm running xampp on Windows. I'm currently trying to get familiar with the laravel framework. Now, when thats pointed out. How can i be able to access my laravel application/website direct within the root?
Example,
What I'm doing now is: localhost/laravel/public/about (to see the
about page)
What i want to do is: localhost/laravel/about
Any good solutions for this? do i need to add a .htacess file on the root folder of laravel? (not the public one).
Any suggestions?
Easiest way is create .htaccess file in your Laravel root with following content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
It should be redirected easily.
Reference: https://coderwall.com/p/erbaig/laravel-s-htaccess-to-remove-public-from-url
Here's how I did it.
Edit your Windows Host file - C:\Windows\System32\drivers\etc\hosts
Edit the Apache vhosts file - Drive-Letter:\xampp\apache\conf\extra\httpd-vhosts.conf
Add an htaccess file to the laravel/public folder (if its not already there)
Restart Xampp apache server
Windows can be a real PITA when trying to edit the Hosts file because of the User Account Control. Since I work on all kinds of small hobby projects, I have to edit this file all the time so this is what I do.
Install PSPad. It loads really fast and you can bookmark files for easy loading/editing. Sublime Text also works well if you load the two files I mentioned above and save the workspace as a new project.
Right-click on the PSPad (or other editor) program shortcut and choose 'Run as Administrator'. You cannot save changes to the Hosts file unless you do this.
Open the Windows Host file in the editor. This file does not have a file extension, so you have to choose "All Files" in the File Open dialog to even see the file.
At the bottom of the file, add this:
127.0.0.1 laravel.dev
This tells Windows to point the web browser to localhost whenever you enter laravel.dev in the browser's address bar.
Save the file.
Open the xampp Apache httpd-vhosts.conf file.
At the bottom of the file, add this: (I am assuming xampp is installed at the root of the D: drive)
<VirtualHost *:80>
ServerName laravel.dev
DocumentRoot "D:/xampp/htdocs/laravel/public"
<Directory "D:/xampp/htdocs/laravel/public">
</Directory>
</VirtualHost>
Add an htaccess file to your laravel/public folder (if its not already there).
I think the default htaccess file that comes with L4 looks like this:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Restart your xampp apache server.
Open a web browser and type in the address bar - http://laravel.dev
That will take you to the index.php file in the "public" folder.
To get to the About page, I think the address would be http://laravel.dev/about
Move the contents of the /public folder down a level.
You'll need to update the include lines in index.php to point to the correct location. (if it's down a level, remove the '../').
BEST Approch: I will not recommend removing public, instead on local computer create a virtual host point to public directory and on remote hosting change public to public_html and point your domain to this directory. Reason, your whole laravel code will be secure because its one level down to your public directory :)
METHOD 1:
I just rename server.php to index.php and it works
METHOD 2:
Here is my Directory Structure,
/laravel/
... app
... bootstrap
... public
... etc
Follow these easy steps
move all files from public directory to root /laravel/
now, no need of public directory, so optionally you can remove it now
now open index.php and make following replacements
require DIR.'/../bootstrap/autoload.php';
to
require DIR.'/bootstrap/autoload.php';
and
$app = require_once DIR.'/../bootstrap/start.php';
to
$app = require_once DIR.'/bootstrap/start.php';
now open bootstrap/paths.php and change public directory path:
'public' => DIR.'/../public',
to
'public' => DIR.'/..',
and that's it, now try http:// localhost/laravel/
Set you document root for apache to the public folder, and not the laravel folder. This is the simplest technique and recommended for production environments.
I'm using L5, This works for me fine:
Rename the server.php in the your Laravel root folder to index.php
copy the .htaccess file from /public directory to your Laravel root folder.
-- Thatz it!!!
I've been struggling with this problem too but i've found a simple solution that only requires you to create another .htaccess at the root of your application.
The .htaccess itself should contain this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^{yoursite}.{extension} [NC]
RewriteRule (.*) http://www.{yoursite}.{extension}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
The complete system keeps working but it redirects to the /public folder.
This is how I solved the problem for myself.
Hope it helps!
Cheers.
Add following code to htaccess file. It may helps you.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Add following code in your .htaccess (if not exist create a .htaccess on laravel root directory)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Source : http://tutsnare.com/remove-public-from-url-laravel/
at Source you also get another method to do same.
Update : Preferred way to do it is make change in directory structure which explain in source URL.
just in simple step i did in laravel 5
make .htaccess like this in laravel folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ ./index.php [L]
</IfModule>
then rename your server.php to index.php
that it it will work
or if you just doing local development
run this comman php artisan serve
it will start local server at localhost:8000 (port may vary)
You can use symlinks or edit the httpd.conf file.
Check my answer to another similar question. I hope that it helps.
If you don't wish to go through the stress of configuring .htaccess file,
you could use PHP Built-in Server by doing this:
From your command utility, cd into laravel\public
The run: php -S localhost:8000
After you can access your website by going to:
http:://localhost:8000
works without appending public
See the official manual to learn more:
http://php.net/manual/en/features.commandline.webserver.php
Go to project folder using cmd and type "php artisan serve".
Now navigate to: localhost:8000
I have found geart flow to work with laravel localy.
What you can do is to configure xampp a bit. At your xamp's httpd.conf file you have to find document DocumentRoot and <Directory>. Change root directory to yours laravel public folder and restart apache. Since when you can access your project simplly just typing localhost. Now if you want you can change your host file and rewrite local dns, for example: 127.0.0.1 example.laravel.com and now you can access your project with real url. It may look bit complicated, but it's not.
Alternative to that would be php artisan serve. You can start server on different ports and when re-write hosts file.
You could add some features to improve your workflow even more, for example vagrant or ngrok. You can share your project for live presentation (speed may be issue here).
Need to remove public segment in the larvel4 app
Laravel 4 requires you to put your app code one level higher than the web root, and this causes problems for some developers that are stuck on shared hosting and that doesn’t allow a setup like this. It’s actually really easy to get around it. I read that some L4 specific packages could have problems on a setup like this, but I didn’t experience anything like that with any package yet.
So first install L4 somewhere you like. I liked the article Niall wrote on keeping the base L4 app up to date, so go and check that out: Installing and Updating Laravel 4
I find it’s enough for this example to simply clone the repo (assuming you have composer installed globally, if not, go to http://getcomposer.org/):
git clone -b develop git://github.com/laravel/laravel.git app_name
php composer install
Note that we are cloning the develop branch since L4 is still in beta at this time.
So to remove the “public” part from your URL, simply move all files and folders from public to your app root and you’ll end up with a folder structure like this:
/app
/bootstrap
/packages (copied from /public)
/vendor
.htaccess (copied from /public)
artisan
composer.json
favicon.ico (copied from /public)
index.php (copied from /public)
robots.txt (copied from /public)
server.php
Now we need to edit our paths in index.php:
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
And then just set the public dir in out /bootstrap/paths.php file:
'public' => __DIR__.'/..',
this is my suggession
You need to do following things:
first copy all the contents of the public directory in your root directory i.e. bring the contents of public folder 1 step up.
modify the contents of index.php
From =>
require __DIR__ . "/../bootstrap/autoload";
$app = require_once __DIR__ . "/../boostrap/start.php"
To =>
"require __DIR__.'/bootstrap/autoload.php';"
"$app = require_once __DIR__.'/bootstrap/start.php';
and also contents of bootstrap/paths.php
From => 'public' => __DIR__.'/../../',
To => 'public' => __DIR__.'/..',
3.Then finally create .htaccess file in your root directory and write this.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Simple Steps To follow:
Rename server.php (In Root directory) to index.php
Copy .htaccess file from public directory to root directory
rename the server.php to index.php and copy .htaccess from /public is the right way.
If you send your app online,just change DocumentRoot to the path of public.
if you remove public from url first of all move index.php and .htaccess file from public folder to root of the laravel and change in index.php file
require DIR.'/../bootstrap/autoload.php';
$app = require_once DIR.'/../bootstrap/start.php';
to
require DIR.'/bootstrap/autoload.php';
$app = require_once DIR.'/bootstrap/start.php';
and run the program
This has been asked before many times. I had the same problem. I solved it by using vhosts and .htaccess files. I wanted to write about solution on both XAMPP on Windows and LAMP installation on Ubuntu. My configuration on windows:
My aim was to reach my application by entering the uri below
http://localhost/subdir
c:\xampp\htdocs\subdir\ # this was laravel root directory
c:\xampp\apache\conf\extra\httpd-vhosts.conf # this virtual hosts file
I used original .htaccess file from Laravel website (and remember .htaccess file must be in public directory) but I just added one line which is
RewriteBase /subdir (just below RewriteEngine On)
In addition, in httpd-vhosts file you should add your subdirectory alias like that:
Alias /subdir
"C:/xampp/htdocs/subdir/public"
<Directory "C:/xampp/htdocs/subdir/public">
Order allow,deny
Allow from all
Options All
AllowOverride All
Require all granted
</Directory>
Hope everything is clear with my explanation. This answer can be applied on unix based systems easily.
I'm developing an application in Symfony and on localhost (XAMPP) I want to simulate the same conditions as on the webserver.
The web server is configured as follows:
/www => mydomain.com
/foo => foo.mydomain.com
/bar => bar.mydomain.com
...
I'm going to put my Symfony application into /www direcotry so there'll be:
/www
/www/apps
/www/apps/frontend
/www/apps/frontend/...
/www/apps/backend
/www/apps/backend/...
/www/cache
/www/config
... and so on...
/www/web
The thing is that the document root is still set to the /www directory but Symfony expects it in the /www/web.
Of course it will work if I call http://mydomain.com/web but I guess you understand this is quiet stupid solution.
So my question is: Is there any way how can I change/bypass the default document root setting using .htaccess or whatever?
EDIT: I solved it.
I don't know much about Symfony but /web is supposed to be the document root. All the other directories should be outside the document root for security reasons for one, and to avoid the /web part in the URL for another. But it looks like you already know that.
If you can edit the web server's configuration, try to reflect that and set DocumentRoot to the web directory.
If you can't do that: It's not possible to change the DocumentRoot in a .htaccess file but it is possible to rewrite all requests so they go to /web internally using mod_rewrite. It's kludgy, but probably the best solution if you can't influence DocumentRoot.
I'm not a mod_rewrite guru so I can't provide an example (I would have to test it first and I can't do that right now) but I'm sure somebody will. Maybe add the mod_rewrite tag to your question.
Update: Untested but should work. Put into a .htaccess file in /www:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/web/
RewriteRule .* /web/%1 [QSA]
you would then need to change your configuration files to use http://www.domain.com/ instead of http://www.domain.com/web/ of course.
I can't say whether that interferes with any other .htaccess rules on the Symfony end - you'd have to try out.
I you got hand on apache config, the better is to move document root from /www to /www/web in you virtualHost config and allow php (if restricted by open_basedir configuration directive) to access the whole /www directory.
Change the way symfony expects your directory to be named :
// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
$this->setWebDir($this->getRootDir().'/www/or/whatever/directory');
}
}