Pretty urls not working (404) – Router does nothing

Notice: This thread is very old.
romanko
Member | 4
+
0
-

Hello,

I want to implement pretty urls on my page, e.g. like that: localhost/example/news/show/6
I get only 404 Not Found when navigating my browser to that url.

Code in my RouterFactory:

public static function createRouter()
{
        $router = new RouteList;
        $router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');
        return $router;
}

Part of the template with link:

<p> {$new->text|truncate:50:" ..."} <a n:if="strlen($new->text) > 50" n:href="News:show $new->id">>Show the whole article</a></p>

Presenter of the page link is pointing to:

<?php
namespace App\Presenters;

use Nette,
    Nette\Application\UI\Form;


class NewsPresenter extends BasePresenter
{
    /** @var Nette\Database\Context */
    private $database;

    public function __construct(Nette\Database\Context $database)
    {
        $this->database = $database;
    }

    public function renderShow($id)
    {
        $new = $this->database->table('news')->get($id);
        if (!$post) {
            $this->error('Post not found');
        }
        $this->template->new = $new;
    }
}

I am using apache2, linux mint 17.2 64bit,
access rights are set to +rwx to entire folder where my project resides,
mod_rewrite is enabled.

When I change Router to SimpleRouter in RouterFactory, everything works, except URL parameters are used for routing, what is not acceptable.

Does somebody know what is going on?
Thank you

Aurielle
Member | 1281
+
0
-

Are you getting 404s from Apache or Nette?

romanko
Member | 4
+
0
-

From Apache

Aurielle
Member | 1281
+
0
-

Then the problem most definitely is not in your code, but rather in Apache configuration. Double check the mod_rewrite settings, you may need to add RewriteBase directive.

David Matějka
Moderator | 6445
+
0
-

Check that AllowOverride directive is set to All

romanko
Member | 4
+
0
-

ModRewrite enabled
AllowOverride set to all (was None before)
Apache restarted

Still doesn't work.

GEpic
Member | 562
+
0
-

romanko wrote:

ModRewrite enabled
AllowOverride set to all (was None before)
Apache restarted

Still doesn't work.

I had the same problem and I searched for a long time, this works for me: (in www folder of course)

<IfModule mod_rewrite.c>
	RewriteEngine On
	# RewriteBase /

	# prevents files starting with dot to be viewed by browser
	RewriteRule /\.|^\. - [F]

	# front controller
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz|map)$ index.php [L]
</IfModule>

Last edited by GEpic (2016-01-07 16:20)