Jump to content

Users display page rewrite url?


chuguruk
 Share

Recommended Posts

Hi there,

Goal:

user profile visible as:

http://mysite.com/username

So far visible as:

http://mysite.com/user.show?user=username

404 template:

<?php $username=$input->get->user;?>
<? $hello = $users->get($username);
echo $hello->name;
echo $hello->id;?>

I have added this to .htacces

RewriteRule    ^[A-Za-z-]+/([A-Za-z0-9-]+)/?$   user.show?user=$1       [NC,L] 

But it doesn't work.

It would be much better to not use 404 template.. Any idea how to get this working?

edit:

I've added page and template "show" with the above code.

I have added this code to header.inc

<?/**
 * This hook modifies the default behavior of the Page::path function (and thereby Page::url)
 *
 * The primary purpose is to redefine blog posts to be accessed at a URL off the root level
 * rather than under /posts/ (where they actually live). 
 *
 */
wire()->addHookBefore('Page::path', function($event) {
  $page = $event->object;
  if($page->template == 'show') {
    $event->replace = true;
    $event->return = "/$page->name/";
  }
});?>

Seems like I'm missing something as it doesn't work for me.

And I can't access users path anyway as it's restricted, right?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...