I am reading Laravel4 quick start tutorial
Laravel4 quick start
I have installed laravel4 on Wamp server in Windows . I was able to access home page which says "you have arrived".
Later in ther router.php I have added only one router as per quick start guide, but for some I am getting this error.
Error:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Router.php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/users', function() //this one i hav added
{
die;
return 'Users!';
});
config.php
'debug' => true,
'url' => 'http://localhost:99',
'timezone' => 'UTC',
'locale' => 'en',
Do not prefix the route with a slash. Use users rather than /users.
I had exactly the same problem today and it took a while to resolve it, but here's how I did it. In this example I created a WAMP Apache Alias 'lava', so http://localhost/lava/ took me to the "You have arrived" page successfully. However even trying a really basic route of:
Route::get('test', function()
{
return "hello?!";
});
Would give me the NotFoundHttpException errors the same as you. To get routing working I did this:
Ensure mod_rewrite is enabled (WAMP does it by default, but double-check)
Ensure open_ssl is enabled (easy to do via the WAMP tray icon)
Edit app/config/app.php and set the url to match your alias, so in my case:
'url' => 'http://localhost/lava/',
Edit public\.htaccess - you can use the one the QuickStart recommends, but you need to change it in 2 places:
```
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /lava/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /lava/$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
```
In the above I've added the RewriteBase line which matches the alias, and also added the alias in the RewriteRule regexp.
The above for me works fine (Windows 7, WAMP) although the .htaccess file is no use when deployed to a live server that doesn't use the same alias.
Trying going to index.php/users. If this loads then you need to setup url rewriting in the htaccess file.
Related
I am having a small issue creating a dynamic sitemap.xml for the site.
My routing file:
Route::get('sitemap.xml', [
'uses' => 'PageController#sitemapXml',
'as' => 'user.page.sitemapxml'
]);
My controller:
public function sitemapXml(){
....
$content .= '</urlset>';
return response($content, 200)->header('Content-Type', 'text/xml');
}
My issue:
To access get the correct response i have to use the following route:
www.mysite.com/index.php/sitemap.xml
However, if i do www.mysite.com/sitemap.xml, i get a 404.
If i manually add the sitemap.xml file in my public folder, i can access the file i just added, but not the dynamic one created in my controller.
My research:
Its probably a problem with the server and not laravel itself. Apparently, .xml extension are not processed through the normal routing.
It suggests adding:
location = /sitemap.xml {
try_files $uri $uri/ /index.php?$query_string;
access_log off;
log_not_found off;
}
that did not work.
I also tried the changing my .htaccess to this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
as specified in the docs
My question:
Is their anything I can do laravel-wise to handle .xml requests?
Also, if you could guide me towards anything that might help me understand this process better, its very welcomed.
Thank you in advance for taking the time to help
UPDATE:
if instead of using my localhost, i use "php artisan serve", things work correctly without any issue.
I found the answer on this link:
https://laravel.io/forum/09-15-2015-removing-indexphp-from-url-laravel-5116
I changed my .conf file and voila.
Hope this helps you
Just to clarify: Nothing wrong with Laravel. More server specific.
I am new in LARAVEL framework and I want to run a controller with just function of view a page
class TestController extends BaseController {
public function index()
{
return View::make('hai');
}
}
I set the routing in routes.php file as given below
Route::get('test','TestController#index');
I tried to run in mozilla with
localhost/laravel/public/test
but it shows
Not Found
The requested URL /laravel/public/test was not found on this server.
is there any problem in my .htaccess page ?
<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>
Any body please help me.
I'm assuming that you are on Ubuntu machine. To make it work, at first, enable the rewrite module by executing following command in the terminal
sudo a2enmod rewrite
Second, find "apache2.conf" file in your system, mine is located in
/etc/apache2/apache2.conf
In this file, find the following snippets of code:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change "AllowOverride None" to "AllowOverride All". Save the file and restart the apache server by executing following command
sudo service apache2 restart
This should solve the issue. Cheers
Precondition: you will know that you have htaccess working, if when you first installed laravel and went to localhost/laravel/public/, you'd see the laravel logo.
The route is:
Route::get('/', function()
{
return View::make('hello');
});
Regarding Your route: you don't need to explicitly state the function (#index) in the route. Laravel has a default path it follows based on the HTTP request type. Check here (under the heading Actions Handled By Resource Controller) for more details on that.
Simply I refer you not modifying .htaccess file. From http://tisuchi.com/easy-way-handle-routing-laravel/:
Static Page Handling
Handling static page in laravel is one of the easiest way to handle
route. Open app/routes.php file and deleted everything from that.
Assume that, we are try to route into our following pages- home
(example.com), about (example.com/about), contact
(example.com/contact). To do so, just write following code in your
routes.php file-
/**
* Static page code
*/
Route::get('/', function(){
return View::make('home');
});
# For example.com/about
Route::get('about', function(){
return View::make('about');
});
/**
* Naming Route for static Page
*/
# For example.com/contact
Route::get('contatct', array('as' => 'contact', function(){
return View::make('contact');
}));
If you are really new in Laravel, highly recommend to look into following 2 tutorials-
http://freshwebdev.com/best-laravel-tutorial-beginners.html
http://tisuchi.com/easy-way-handle-routing-laravel/
Ofcourse, don't forget to take a look into official page of laravel.com.
Hope, it will work for you.
Have fun...
I have a website using MODx Revolution (2.2.10-pl, advanced install), let's call it www.example.com, which I want to be accessible with both http and https.
to achieve this, I tweaked the site_url context setting to be [[++url_scheme]]www.example.com/. Links created using [[~id]] seem to be alright, however, sometimes, the generated links are really weird. My interpretation is that the code to create links programmatically doesn't work with my settings, but I don't know why, or how else I would go about enabling both http and https.
Question first, examples below: How should I set the site_url or any other site/context setting so that links on my site work with both http and https? Optionally, is the behavior I see a bug, or expected behavior given Revolution's tag evaluation semantics?
Misbehavior examples:
When I click on "View" in the manager for a resource with the alias example, the address that is opened is
https://www.example.com/xyz/[[++url_scheme]]www.example.com/example/
where xyz is my manager URL. The expected URL is of course
https://www.example.com/example/
Another case where this happens is for failed logins; my login call looks like this (minus irrelevant parts):
[[!Login? &redirectToOnFailedAuth=`[[++unauthorized_page]]`]]
The unauthorized_page's expected full URL is
https://www.example.com/special/401
but the URL which is opened for a failed login as username is
https://www.example.com/[[++url_scheme]]www.example.com/[[++url_scheme]]www.example.com/special/401?u=username
The second example is the same for http, except for the scheme, of course; I haven't logged into the manager with http.
EDIT
.htaccess at the webroot:
RewriteEngine On
RewriteBase /
# redirect all requests to /en/favicon.ico to /favicon.ico
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/favicon.ico$ favicon.ico [L,QSA]
#RewriteRule ^(en|nl|de)/favicon.ico$ favicon.ico [L,QSA]
# redirect all requests to /en/assets* /assets*
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/assets(.*)$ assets$2 [L,QSA]
#RewriteRule ^(en|nl|de)/assets(.*)$ assets$2 [L,QSA]
# redirect all other requests to /en/*
# to index.php and set the cultureKey parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
#RewriteRule ^(en|nl|de)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
.htaccess in the manager's directory:
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/xyz/$1
The problem is with $modx->makeUrl(). For example, for the
[[!Login? &redirectToOnFailedAuth=`[[++unauthorized_page]]`]]
call, in core/components/login/controllers/web/Login.php:
public function checkForRedirectOnFailedAuth(modProcessorResponse $response) {
$redirectToOnFailedAuth = $this->getProperty('redirectToOnFailedAuth',false,'isset');
if ($redirectToOnFailedAuth && $redirectToOnFailedAuth != $this->modx->resource->get('id')) {
$p = array(
'u' => $this->dictionary->get('username'),
);
$message = $response->getMessage();
if (!empty($message)) $params['m'] = $message;
$url = $this->modx->makeUrl($redirectToOnFailedAuth,'',$p,'full');
$this->modx->sendRedirect($url);
}
}
the last two lines do a redirect to a URL generated with makeUrl, which will be something like [[++url_scheme]]www.example.com/etc (note: I'm not 100% sure here, as I can't easily look at the raw URL. The conclusions still hold, though). If the URL is simply shown on the page, this is no problem, because MODx will parse the tag before inserting it into the html output. However, as the URL is used directly for the redirect, no such replacement takes place, and the browser interprets it as a relative URL, resulting in target URLs such as https://www.example.com/[[++url_scheme]]www.example.com/etc.
So much for the problem. To avoid this, site_url must be a literal value without any tags in it. As a workaround, I now use the following snippet as the first thing in my template:
$modx->config['site_url'] = $modx->config['url_scheme'] . substr($modx->config['site_url'], strlen('[[++url_scheme]]'));
return '';
together with a [[++site_url]] of
[[++url_scheme]]www.example.com/
Note that some parts of MODx don't seem to notice this update, which is why it's important to still use [[++url_scheme]] in your site_url. As far as I can tell right now, the parts that don't see the update, stuff like [[~id]], work properly with url_scheme.
EDIT this does of course only fix the "View" buttons in the manager if you tweak the manager templates accordingly.
WARNING this is of course very hacky, and not yet tested very well. The fact that some features do not see the overwritten value means that you're introducing an inconsistency into your website, which may lead to subtle errors! If a more clean solution comes up, go for it!
Why i can't get an image to work. I'm trying this:
background-image: url(jBootstrap/images/ui-icons_222222_256x240.png);
and it doesn't work. When i'm trying to access it trought URL i get an error:
Asset [stylesheets/jBootstrap/images/ui-icons_222222_256x240.png] was unable to be processed.
Can't get any images, tried in many variations of directories and still doesn't work. When i'm doing this on plain html-css it works perfectly, but not in laravel. What am I doing wrong ?
btw, i'm using Basset if it helps.
EDIT 1
Also including the additional information about a partial structure of my public folder and html link generated by basset:
public/
stylesheets/
jBootstrap/
images/
ui-icons_222222_256x240.png
main.css it contains the background-image...
when including the css file, in source code i see:
<link rel="stylesheet" type="text/css" href="http://localhost/Job/worker/myapp/public/7n3C5wypAmTi8VT8/application/stylesheets/main.css" />
Edit 2
Adding my public/.htaccess file:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Edit 3
Tried another way:
public/stylesheets/main.css
public/stylesheets/abc.jpg
in main.css I have code: body { background-image: url('abc.jpg') } and i'm getting nothing ...
Please help, struggling 2 days now ...
Found the problem... It was Basset package, it wat required to put $collection->apply('UriRewriteFilter'); into configurations.
I would naturally assume that one (or both) things are incorrect here:
Your .htaccess file is not checking for existing files when rewriting. Check to see if RewriteCond {%REQUEST_FILENAME} !-f exists in that file.
You are not requesting your background image from the root, i.e. absolutely. Try requesting the resource using a leading slash. For example, instead of calling foo.png, try calling /foo.png.
Try using setArguments('../') on your collection
'collections' => array(
'application' => function($collection) {
$collection->add('../vendor/twitter/bootstrap/less/bootstrap.less')->apply('Less');
$directory = $collection->directory('assets/stylesheets', function($collection) {
$collection->add('main.css');
})->apply('UriRewriteFilter')->setArguments('../')->apply('CssMin');
}
),
This did the trick for me.
I've come across a problem which i cant seem to figure out, i use the jQuery address plugin to store history and enable deep linking, and a typical url after a click would look like this:
http://mysite.com/#!/page
Problem here is i need rid of the last / so i need it to look like this:
http://mysite.com/#!page
I'm using plugin version 1.2 - the latest is 1.4. When i use 1.4 my hashbang #! disappears..
Anyone know why? even so, the updated version produces the same problem.
Reasons to fix this are i use 301 redirects to 'Pretty URL's' if an ?_escaped_fragment_= is requested. So this:
http://mysite.com/data/#!page1
would become:
http://mysite.com/data/page1
currently it does this: mysite.com/data//page1
here is the .htaccess rewrite:
<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite current-style URLs of the form 'index.php?url=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
and here is some relevant PHP i use on page load:
if ($fragment = $_GET['_escaped_fragment_']) {
// OPTION 1: if Google is reqesting an '_escaped_fragment_=' page, then redirect to a clean URL
header("Location: $base/$fragment", 1, 301);
exit;
}
Any help on how to make this situation better is appreciated.. I don't want 'use the HTML5 History API' as ive explored this option already.
This line of code can help!
$.address.strict(false);