I am removing public from laravel url by using .htaccess i am writing the code on my htaceess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
htacces file is in the root of laravel and my mode_rewrite also enable
after that i am getting error Sorry, the page you are looking for could not be found. but i can still get welcome page by http://localhost/laravel/public/ please solve my issue
Your web server configuration is wrong. You should point your web server to a public directory.
For example, if you're using Apache, you should set up it like this:
<VirtualHost *:80>
ServerName myapp.localhost.com
DocumentRoot "/home/vagrant/projects/myapp/public"
<Directory "/home/vagrant/projects/myapp/public">
AllowOverride all
</Directory>
</VirtualHost>
In XAMMP, MAMP, OpenServer etc. you need just to change root directory to Laravel's public directory.
Also, don't forget to restart your web server to make everything work.
Related
Hi i have zero knowledge about setting up domain and stuff, all i did was search the net. And i think i do not get the correct keyword from my search since i just can't find the correct answer for my problem.
now i need your help guys. please, i want them to work those 2 domains and their respective DocumentRoots
this is my host file setup
127.0.0.1 mydomain.com
127.0.0.1 mydomain.net
this is my vhost file setup
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/mydomain-com"
ServerName mydomain.com
<Directory "/opt/lampp/htdocs/mydomain-com">
Options All
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/mydomain-net"
ServerName mydomain.net
<Directory "/opt/lampp/htdocs/mydomain-net">
Options All
AllowOverride All
</Directory>
</VirtualHost>
but when i go to mydomain.net it goes to mydomain.com it seems only mydomain.com is working
this is my htaccess file for both
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1
I don't know the reason but, when i reinstall xampp and include core files now its working just fine.
I assume the previous developer played around the config files and messed it up. geez.
without proper investigation of the real problem, this really is not the correct answer but i would like to close this since i'm all good now.
Trying to get a test Laravel project running on the server. If I navigate to the sites URL I am presented with the Laravel welcome screen but none of the routes are working.
To fix this I have changed the .htaccess file as specified by the laravel website.
The problem is in order for the .htaccess to be utilised I have to "AllowOverride all" in my virtualhost file which is causing a 403 to be presented instead of the welcome page.
The error I'm getting is:
Forbidden
You don't have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request
Just for testing purposes I have given the entire laravel folder 777 to make sure there isn't a a file permission issue.
Any help would be greatly appreciated. Thanks
Content of my .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Content of my VirtaulHosts:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/testProject1/public
DirectoryIndex index.php
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<Directory> must refer to an absolute path, whereas <Location> can refer to a path relative to the document root.
As such, change:
<Directory />
to:
<Directory /var/www/testProject1/public>
And don't forget to reboot Apache.
I was using Capistrano to deploy my source code to beta and live server.
when I deploy it to the beta server the URL looks like deploy.abc.com/project_name/current
I just want to know the way to remove /current from the URL so it will look like deploy.abc.com/project_name. I know this should be done using .htaccess and mod-rewrite. But I have no Idea.
You can modify the VirtualHost (maybe in etc/httpd/vhosts/*.conf):
<VirtualHost *:80>
DocumentRoot /home/deploy.abc.com/www/current #this line change the url
#some code
</VirtualHost>
or the .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
#some code
RewriteRule ^(.*)$ current/$1 [QSA,L]
</IfModule>
I'm writing my steps and findings here so you can see what I've tried and what results I got. Any advice would be welcomed. I followed the comments in this answer.
I'm running Laravel 4, using XAMMP version 1.8.2 with PHP 5.4.19 and Apache 2.4.4 on a Windows 7 machine and I'm simply still trying to get a local instance up and running.
In my case: http://localhost/sos/sos_public/ is my main screen and that works, but when I try to get to http://localhost/sos/sos_public/signup I get this error: Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException which has been talked about a lot on the net, and then I found GaryJ stating that it might be an .htaccess issue, so I did what he suggested.
My /app/routes.php file looks like this (I've tried this with a / in front of signup too):
Route::get('signup', function()
{
return 'hello!';
});
Route::get('/', function()
{
return View::make('hello');
});
First:
Just for a laugh, see if /index.php/hello works. If so, then it's a .htaccess problem.
http://localhost/sos/sos_public/index.php/signup worked perfectly fine. So it's an .htaccess problem.
My .htaccess file looked like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And:
if you're running Apache 2.4, note the changes since previous
versions, regarding Require all granted and AllowOverride all within a
<Directory />...</Directory> block on your virtual host.
I added this in my httpd.conf file as suggested by Dalton Gore - got the Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException error (changed this directory path to /SOS/sos_public and C:/xammp/htdocs/SOS/sos_public/ and C:/xammp/htdocs/SOS/sos_public - same results):
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory /SOS/sos_public>
AllowOverride all
Require all granted
</Directory>
Next:
Check if anything in .htaccess is working
I added dsjkdsfghk to my .htaccess file and immediately got an error, so I know my .htaccess file is being used.
Then:
Try removing the IfModule conditional. As you've got access to the
host / vhost, you can soon enable that module if it's not - so it
doesn't need be checked on every request. Equally, try moving it out
of .htaccess, and into a <Directory />...</Directory> block in your
vhost - if you've got nothing else in your .htaccess it can then be
deleted as well.
Having an empty .htaccess file caused a 404 error in my browser for http://localhost/sos/sos_public/signup (http://localhost/sos/sos_public/ still worked).
Removing the .htaccess file from C:\xampp\htdocs\SOS\sos_public\ had the same results.
Then:
Try: <VirtualHost *:80> DocumentRoot
"/Users/amiterandole/Sites/laravelbackbone/public" ServerName
laravelbackbone.dev <Directory /> AllowOverride all Require all
granted </Directory> <IfModule mod_rewrite.c> Options -MultiViews
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^
index.php [L] </IfModule> </VirtualHost>
I did that and just like Amit,
I emptied out my htaccess file and tried the above and now nothing
seems to work.
Except where his laravelbackbone.dev pointed to his Sites folder root, I just got an Error 400 - Bad request on both http://localhost/sos/sos_public/ and http://localhost/sos/sos_public/signup when I ran them in my browser.
My httpd-vhosts.conf file looked like this:
<VirtualHost *:80>
DocumentRoot "C:/xammp/htdocs/SOS/sos_public"
ServerName sos.dev
<Directory />
AllowOverride all
Require all granted
</Directory>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</VirtualHost>
and in my .hosts file I obviously had:
127.0.0.1 sos.dev
Lastly:
You've definitely got the conf/extra/httpd-vhosts.conf file be
included (uncommented) within the main httpd.conf?
I have this uncommented - yes.
Another link I tried but to no avail: https://stackoverflow.com/a/17778222/956975 and http://www.epigroove.com/blog/laravel-routes-not-working-make-sure-htaccess-is-working
What should I change where?
What am I missing?
Your ServerName is
sos.dev
And apache take this in consideration, you you must access your routes using:
http://sos.dev/
And NOT
http://localhost/
It might be the error of not enabling rewrite Engine in apache2
In linux,
sudo a2enmod rewrite
sudo systemctl restart apache2
In windows,
You should find httpd.conf file if it's not available in your apache look for apache2.conf file is another name for httpd.conf and enable the rewrite module for more info or here see how to do above-said procedure in this link
Lost httpd.conf file located apache
I'm using .htaccess and mod_rewrite to point to files that reside behind the DocumentRoot. My folder structure looks like this:
home/
webroot/
other_files/
I have a .htaccess file in webroot with the following content:
RewriteEngine on
RewriteRule ^(.*)$ /home/other_files/$1
If I try to access http://example.com/file.html I receive the following error:
The requested URL /home/other_files/file.html was not found on this server.
Is it even possible to load files that are behind the DocumentRoot? If so, can someone point me in the right direction?
I believe you need to add a section with
<Directory "/home/other_files">
(options)
</Directory>
to your server configuration before apache will be able to serve anything from it. For an example, my DocumentRoot is /var/www but there is this section in the default available site:
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
You could then rewrite a URL to go to /doc/ and the server would know where to get the files from.
Just so you know why that rule doesn't work:
The reason that it isn't able to rewrite to /home/other_files/file.html is that mod_rewrite is parsing the path as /home/webroot/home/other_files/file.html since from mod_rewrite's point of view the preceding slash is equivalent to your document root of /home/webroot.
Ryan Ahearn's suggestion is a decent one, and is likely the route you want to go.
The credit goes to Ryan Aheam, but I'm going to spell it out. I'm a beginner and even with Ryan's answer I had to experiment with a few things to get the syntax right.
I wanted my DocumentRoot to be my cakephp directory. But then I had a Mantis Bug tracker that was just regular PHP and so not in the cakephp directory. The the files below I have the following working.
http://www.example.com : served by /var/www/cakephp
http://www.example.com/mantisbt : served by /var/www/html/mantisbt
File /etc/httpd/conf/httpd.conf
Alias /mantisbt/ "/var/www/html/mantisbt/"
<Directory "/var/www/html/">
AllowOverride All
</Directory>
<VirtualHost *:80>
ServerAdmin me#my_email.com
DocumentRoot /var/www/cakephp
ServerName my_website.com
<Directory /var/www/cakephp/>
AllowOverride All
</Directory>
</VirtualHost>
File /var/www/cakephp/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^mantisbt/?$ /mantisbt/ [NC,L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>