Laravel routes not working except for root - php

I have been spending hours on this issue and hope to find my way out. I have set up laravel correctly, created a project myapp
My route.php file just contains
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/users', function()
{
return 'Users!';
});
When I run
http://localhost/myapp/public/
I get the laravel start page correctly
When I run
http://localhost/myapp/public/users
I get
The requested URL /myapp/index.php was not found on this server.
I don't know why its looking for index.php.
When I run
http://localhost/myapp/public/index.php/users
I get a page with text "Users". I should obtain this page when running
http://localhost/myapp/public/users
instead.
Below is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
Rewritebase /myapp/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Any ideas? Am running a Apache on Linux.

Your RewriteBase is set to /myapp/ but your index.php file is in /mayapp/public/ is it not?
As such, I think you'll find the RewriteBase needs to be /myapp/public/.

Make sure you have mod_rewrite enabled on apache web server.
Make sure that your vhost config allows and parses htaccess files

Just do this and try to restart the apache.
sudo a2enmod rewrite
To restart apache: sudo services apache2 restart

I ran into same problem with production server, nothing seemed to work, no chmod/s no other solution but adding a simple line to .htaccess worked.
RewriteBase /
Thanks to the thread and user odaria

In your application/config/application.php file change:
'index' => 'index.php',
to:
'index' => '',
That should tell laravel not to use index.php and to rewrite correctly.
It works with standard .htaccess file which comes with laravel (haven't checked if you modified it)

Use this re-write rule:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /my_app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Also, in `application/config/app.php' change:
'index' => 'index.php'
to
'index' => ''

The quickest way is to add a symbolic link in command line:
ln -s your/acutal/path/myapp/public app-dev
Now browse http://localhost/app-dev should work fine as well as all the routes. You can change app-dev to whatever you want as the name.

Related

Laravel 5 - Internal Pages giving Not Found Error

Actually I am deploying my laravel 5 Application on Linode Server.
My client create space for me in such type of path.
var/www/html/abcproject
I point out my godaddy domain to abcproject directory.
Now I have uploaded my all Laravel 5 files on abcproject directory.
My issue is that , my home page is working fine but my internal pages
are giving Not Fount Error.
Suppose when I try to logged in it is giving below error.
Not Found
The requested URL /abcproject/login was not found on this server.
Secondly Laravel 5 URL is getting url like that.
Supposed URL.
http://15.30.19.61/abcproject/index.php/registers
I did not understand where is and what is the issue.
One thing is my project is working fine when I try such type of URL.
http://example.com/index.php/ But In this case my URL Rewriting did not work but project is working like I can logged in, go in different pages, Logout etc.
My HTACCESS FILE
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Thanks
If you are powering your laravel project from a sub folder such as you mentioned above:
http://15.30.19.61/abcproject
You should add this to your .htaccess file under RewriteEngine On.
RewriteBase /abcproject
I also faced a similar issue with LAMP configuration and I resolved by enabling rewrite rules of apache. If some needs details then it can be referred at the below blog notes
http://ankgne.com/post/setting-up-digital-ocean-for-laravel-application
Step 1: Enabling mod re-write using sudo a2enmod rewrite
Step 2: Allowing the laravel .htaccess (in public directory of laravel page)
file to apply rewrite rules
sudo vi /etc/apache2/sites-available/000-default.conf and adding below lines
Note: Change "/var/www/html" to "path of laravel public folder"
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
. . .
Step 3: Restarting web server using sudo systemctl restart apache2

Laravel - How to remove index.php from Laravel in windows xampp

Problem:
my routes not working except the root home page, I'm searching for two days to find a solution to this problem and what I found that I should change .htaccess file but solutions didn't fix any for my case, at first the url localhost/quotes/public was working well with me, but at some point I'm not sure what is it this issue showed up
what I tried:
create another route and I made sure that no routes are working only
home route, still not working except home
tried to change OverrideMode on my XAMP from None to All, didn't fix any
tried to type manually localhost/quotes/public/index.php BOOM everything
works ..
my htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
working on:
Windows 10
XAMP
Laravel 5.2.35
The problem is that your .htaccess is rewriting everything to the frontcontroller, which is normally located at {host}/index.php. In your application however it is located at {host}/quotes/public/index.php.
So you have 2 options:
1. virtual host
Set up a virtual host in your XAMPP Apache that points ie. myapp.local to htdocs/quotes/public Here is an example of how to achieve this: how to create virtual host on XAMPP. (Don't forget to add the host to your hosts file and have it point to your local macine on 127.0.0.1) You can then access your application on myapp.local/whatever-route-you-define. Alternatively you forget about XAMMP and install the homestead virtual machine, which comes preconfigured for this.
2. rewrite rule
Change you rewrite rule to rewrite all requests to quotes/public/index.php in stead of index.php. I'm no htaccess expert, but I believe it should be as simple as changing this:
RewriteRule ^ index.php [L]
to this:
RewriteRule ^ quotes/public/index.php [L]
Do note that you'll still need to access your application trough localhost/quotes/public/whatever-route-you-define which is not ideal imo. Your dev version should be as close to your live version as possible, and if you start working with absolute and relative paths and stuff in your code things will become a mess sooner rather then later.
Personally I would go for Homestead, I use it all the time and it works great once you have it running.
Btw, the reason why localhost/quotes/public/index.php is working for you right now is because RewriteCond %{REQUEST_FILENAME} !-f tells Apache not to rewrite any requests to files that actually exist (otherwise you wouldn't be able to access static assets like your css).
The .htaccess file must be at the root of the application.
Add this in this file :
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
Assuming you haven't touched the original architecture of Laravel, and that public data is still in the same place : the public/ folder
You can also follow this good tutorial
Let me give you an example of the way I have my routes setup.
In app\Http\routes.php, here are three sample routes that I have.
Route::get('/', function () {
$values = app('App\Http\Controllers\KeywordController')->index();
dd($values);
return view('welcome');
});
Route::get('googlefile', function () {
$output = app('App\Http\Controllers\KeywordController')->printToFileGoogle();
dd($output);
});
Route::get('bingfile', function () {
$output = app('App\Http\Controllers\KeywordController')->printToFileBing();
dd($output);
});
I have WAMP setup on my environment. I have made a controller at app\Http\Controllers\KeywordController.php. If my browser is set to localhost/googlefile, then it will goto the method printToFileGoogle() in KeywordController.php.
Please try something similar to this and tell me if you get an error and if you do what error you get.

Symfony 2 project in nested directory

I need to deploy a Symfony 2 project in nested directory on production server. Effectively, this would mean that all URLs are prefixed with /subdirectory/ path, i.e.
http://host.com/subdirectory/project/web/app.php/survey
I don't need URL rewriting and are am not going to set it up. The app should work when accessed via above URL only.
The problem I have is that all links generated by path and asset Twig functions are relative to server root (/), and not subdirectory the project is in (/subdirectory/). Is there any config parameter in Symfony 2 to override relative paths globally?
I tried to work around that problem by adding HTML tag, but it doesn't work for links.
Update: I owe you further details. I'm running IIS with its version of mod_rewrite, so part of your suggestions may still be valid.
Update: Ideally I would like to see a solution that sets root dir on AppKernel object - method AppKernel::setRootDir() had it existed to complement existing AppKernel::getRootDir().
Strange... with default config, path/asset should handle subdirectories. Have you tried it with symfony distribution out-of-the-box? On localhost im mostly using it this way.
Would you mind posting your config file?
Anyway...
For assets paths you could try to configure:
#config.yml
templating:
assets_base_urls: { http: "http://yoursite.com/dir1", ssl: "https://yoursite.com/dir1" }
(http://symfony.com/doc/current/reference/configuration/framework.html#assets-base-urls)
For router you should read: http://symfony.com/doc/current/cookbook/console/sending_emails.html#configuring-the-request-context-globally
It could give you some ideas about changing router context like:
# app/config/parameters.yml
parameters:
router.request_context.host: example.org
router.request_context.scheme: http
router.request_context.base_url: my/path
Anyway - context is automaticlly set based on request information. Try to debug:
$context = $this->getContainer()->get('router')->getContext();
// you should be mainly interested in:
$context->getBaseUrl();
It is possible to easily create listener class which will manually set your base url if anyhow it is wrong:
class RouterContextListener {
protected $router;
public function __construct(RouterInterface $router)
{
$this->router = $router;
}
public function onKernelRequest(Event $event)
{
$this->router->setBaseUrl('somedir');
}
}
You are looking for RewriteBase rule, add it to your in your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory/project/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
Also take a look onto symfony-standard 2.3 .htaccess file, mb it can help
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
Look at app/config/routing.yml where you import routing from your bundles. Records in that file would look similar to this:
somename:
resource: "#YourBundle/Resources/config/routing.yml"
prefix: /
You can add your subdirectory in prefix, like prefix: /subdirectory
Then all generated URLs will include subdirectory.
To enable it the rewrite module, run "apache2 enable module rewrite":
sudo a2enmod rewrite
You need to restart the webserver to apply the changes:
sudo service apache2 restart
VirtualHost should be like this
ServerName localhost.myproject.dev
ServerAdmin webmaster#localhost
DocumentRoot /var/www/project_path
<Directory /var/www/project_path>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
this option is redirect your index.php, index.html or whatever:
Options Indexes FollowSymLinks MultiViews
it will rewrite your htacces!
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
My solution to this on a local environment was adding the following code in app/config/config.yml
framework:
assets:
base_urls:
- 'http://localhost/symfony_dir/'
No rewrite needed!

Strange situation mod_rewrite and PHP

I do not understand something ...
I have CMS written by me and have some strange problem about hidden error from "mod_rewrite". In apache2 error.log "mod_rewrite" giving :
File does not exist: /home/path/to/request, referer: http://IP/request?view=1
my $_GET / $_POST request are all empty
$_SERVER['REQUEST_URI'] is ok (returns request?view=1)
$_SERVER['QUERY_STRING'] is also empty
also i install Drupal CMS to test is it problem on web server, but Drupal works just fine... then i copied drupal ".htaccess" file to my CMS in order to fix mod_rewrite preferences. (Drupal do not create apache error like my )
No luck, i have same problem again.
also tried with all options in .htaccess from Drupal CMS
I try to turn on RewriteLog (several attempts) but without result, not a single log file was not created.
Am i something missing or ... just my cms sucks
and one more thing, my CMS work just fine on other webserver with exactly the same files .... ?????
RewriteEngine On
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
#tested RewriteRule ^ index.php [L]
#tested RewriteRule ^ index.php [L,QSA]
#tested Options FollowSymLinks
#tested Options -MultiViews
#tested RewriteBase /
P.S. sorry for my bad English
Not sure if that's your whole .htaccess but you need to enable rewrite, here's a rewrite I use and its never failed:
RewriteEngine On
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
The RewriteRule passes everything (.*) to a route parameter in index.php then my router class handles the controller ect, the QSA flag will also allow me to pass extra GET/POST values to any part of the script.
hope it helps
ps I dont add the RewriteCond %{REQUEST_FILENAME} !-d because I dont allow folder views and I dont serve content from a folder, everything goes through a controller inc (images,css,js), so there is no need for this in most cases. And it also protects the folders like core & template ect ;)
finally I found the solution of my problem!
The answer is very,very,very simple...
In apache2 configuration (on Ubuntu) I found the <Directory tag is duplicated by default ... I just erase all directories tags and create one basic.
reload apache2 configuration and every thing starts working just fine

install fuelphp 403 error

I have downloaded fuel unzipped it and placed it in a virtual host(virtual hostX) it comes up as fuel.site
but not the welcome page it just comes up a directory listing
changelog.md
docs(folder)
oil
if I try and go manually to the public folder I get a 403 error
what do I need to configure to get it to run?
I even tried a .htaccess file with
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /fuel/public
RewriteRule ^(.*)$ /fuel/public/public/index.php/$1 [L]
</IfModule>
in it as recommended on another site
If you can't find the answer here: http://docs.fuelphp.com/installation/instructions.html#manual
Could you show me the dir/filestructure? The public/public seems a bit off. And the rewrite base should probably just be /. Like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ /fuel/public/index.php/$1 [L]
# Sometimes it's: RewriteRule ^(.*)$ /fuel/public/index.php?/$1 [L]
</IfModule>
sorry guys i had some errors in my apache setup using mamp now working fine thanks for the help

Categories