chuguruk Posted May 17, 2016 Posted May 17, 2016 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?
adrian Posted May 17, 2016 Posted May 17, 2016 Unless I am missing something obvious, it should just be a matter of enabling url segments on your home template, then using the value of the segment to get the page details for that user name. https://processwire.com/docs/tutorials/how-to-use-url-segments/ 1
chuguruk Posted May 17, 2016 Author Posted May 17, 2016 Unless I am missing something obvious, it should just be a matter of enabling url segments on your home template, then using the value of the segment to get the page details for that user name. https://processwire.com/docs/tutorials/how-to-use-url-segments/ I've tried segments but didn't know I have to turn it on in template.. Thanks! 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now