Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Creating user friendly URL's throughout whole forum

Hey, I was wondering what would be the best way to create better and modify user friendly URL's with .htaccess for the forum, for example instead of it being http://localhost/forum/index.php?p=/discussion/1/something it would be something like http://localhost/forum/discussion/1/something and instead of http://localhost/forum/index.php?p=/profile/edit it would be http://localhost/forum/profile/edit

Comments

  • Options
    joscplanjoscplan
    edited November 2014

    You don't need to do that on the .htaccess you can do it in "dashboard/routes" There you can modify routes to be more user friendly.

    http://vanillaforums.org/page/routes

  • Options

    @joscplan said:
    You don't need to do that on the .htaccess you can do it in "dashboard/routes" There you can modify routes to be more user friendly.

    http://vanillaforums.org/page/routes

    Ah nice, was just wondering how I'd change forum/index.php?p=/profile/1/username to forum/profile/username because it gets their userID and username?

  • Options
    peregrineperegrine MVP
    edited November 2014

    read the documentation on rewrite of urls and the associated config statement and .htaccess changes.

    come back in a month to post more questions, after you take time to read documentation and tutorials.

    you seem to ignore the documentation.

    also try searching the forum and re-reading the links to tutorials provided to you in other discussions.

    if english is not your primary language, post question in your native language, if you don't understand the english language.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    @peregrine said:
    read the documentation on rewrite of urls and the associated config statement and .htaccess changes.

    come back in a month to post more questions, after you take time to read documentation and tutorials.

    you seem to ignore the documentation.

    also try searching the forum and re-reading the links to tutorials provided to you in other discussions.

    if english is not your primary language, post question in your native language, if you don't understand the english language.

    I've read about other posts and I've got pretty URLs enabled but just didn't know how it would go about doing this

    forum/index.php?p=/profile/1/username OR with pretty URL it is forum/profile/1/username to forum/profile/username (Removing the UserID from the link is what I'm basically trying to achieve)

  • Options
    peregrineperegrine MVP
    edited November 2014

    if you remove the userid - it goes to the profile of the logged in user -you. other wise it will go to the profile of the user who indeed not be you. Depends on where you click, there is no one size fits all and if you remove the id via routing you will break other links.

    sounds like a tempest in a teapot.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Removing the ID from all the internal links vanilla creates isn't really possible, but you can access profiles even without the ID:
    http://vanillaforums.org/profile/BIOS

  • Options
    peregrineperegrine MVP
    edited November 2014

    @BIOS said:

    I've read about other posts and I've got pretty URLs enabled but just didn't know how it would go about doing this

    forum/index.php?p=/profile/1/username OR with pretty URL it is forum/profile/1/username to forum/profile/username (Removing the UserID from the link is what I'm basically trying to achieve)

    so your question once again is entirely different then what you posted in you opening post.

    I suggest you read the links on how to ask questions.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    BIOSBIOS New
    edited November 2014

    @peregrine said:
    if you remove the userid - it goes to the profile of the logged in user -you. other wise it will go to the profile of the user who indeed not be you. Depends on where you click, there is no one size fits all and if you remove the id via routing you will break other links.

    sounds like a tempest in a teapot.

    Ah so there's no easy method to do it really then, I was trying to make it so that if you went to either forum/profile or forum/profile/yourUsername (it would go to your profile if as session exists if not it would redirect you to the index) but if you went to another such as forum/profile/SomeoneElsesUsername it would show you their profile.

    @peregrine said:

    It isn't because I'm trying to overall create user friendly URL's, the profile example is just one of the things that I wanted to change it's still the same stuff.

  • Options

    @BIOS your initial question was about how to turn on rewrite rules, that is plain as day.

    You changed the ball park without acknowledging doing so.

    grep is your friend.

  • Options
    AdrianAdrian Wandering Spirit Montreal MVP
    edited November 2014

    @BIOS‌

    Add the following to conf/config.php

    $Configuration['Garden']['RewriteUrls'] = TRUE;

    This is to create "pretty urls" for anyone else looking for the answer. Modifying anything else can be via Routes or .htaccess.

  • Options

    @x00 said:
    BIOS your initial question was about how to turn on rewrite rules, that is plain as day.

    You changed the ball park without acknowledging doing so.

    Nope, i was asking what would be the best way to create user friendly URLs with .htaccess and then someone told me about the routes, I already know how to turn on Rewrite rules, infact it's on by default with the .htaccess that comes with Vanilla just doesn't look great, lol.

    @Adrian said:
    BIOS‌

    Add the following to conf/config.php

    $Configuration['Garden']['RewriteUrls'] = TRUE;

    This is to create "pretty urls" for anyone else looking for the answer. Modifying anything else can be via Routes or .htaccess.

    Yup, already had that before. I was trying to further modify the URLs but it's believed to be not easily achievable without editing the core -- My question has been previously answered.

  • Options
    peregrineperegrine MVP
    edited November 2014

    A few things that might help you in the future.

    see the link on how to ask a question.
    realize if you have so much confusion in your thread, you didn't pose a clear enough question.
    acknowledge that you changed questions mid-stream

    If English is not your native language, perhaps someone can translate the above links to the language you are fluent in speaking and understanding.
    .

    thank you
    exclamation
    exclamation: thank you; exclamation: thankyou
    
        1.
        a polite expression used when acknowledging a gift, service, or compliment, or accepting or refusing an offer.
        "thank you for your letter"
    
    noun
    noun: thank you; plural noun: thank yous; modifier noun: thank-you; noun: thankyou; plural noun: thankyous
    
        1.
        an instance or means of expressing thanks.
        "Lucy planned a party as a thank you to the nurses"
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    @peregrine said:
    A few things that might help you in the future.

    see the link on how to ask a question.
    realize if you have so much confusion in your thread, you didn't pose a clear enough question.
    acknowledge that you changed questions mid-stream

    I never went off topic, you are doing it now by continuing to reply to a thread about English where the answer has already been answered?

    My questions were all regarding the same thing. (Creating user friendly URLs can be related to .htaccess, routes, and once again changing the profile URL would also be related also since what i'm trying to achieve from it is a "user friendly URL".)

    Further replies to the discussion aren't required to the thread as it's already been answered.

  • Options
    hgtonighthgtonight ∞ · New Moderator
    edited November 2014

    @BIOS said:
    I was trying to further modify the URLs but it's believed to be not easily achievable without editing the core -- My question has been previously answered.

    This is actually pretty easy to do.

    1. Create application called 'PrettyURLs'
    2. Extend Vanilla's controllers. E.g.

      class dController extends DiscussionController {
      
        public function Index($DiscusssionStub = '', $Page = '') {
          // Look up discussion ID via discussion stub
          $DiscussionID = $this->DiscussionModel->GetByStub($DiscussionStub);
          // Call the parent index with the proper info
          parent::Index($DiscussionID, $DiscussionStub, $Page);
        }
      }
      
    3. Extend models as necessary in your hooks file.

      public function DiscussionModel_GetByStub_Create($Sender) {
        // Add lookup method here
        // Should return numerical ID
      }
      
    4. Override the associated render functions to use your new scheme. I would use the bootstrap file for this. E.g.

      function DiscussionUrl($Discussion, $Page = '', $WithDomain = TRUE) {
         $Discussion = (object)$Discussion;
         $Result = '/d/'.$Discussion->DiscussionID.'/'.Gdn_Format::Url($Discussion->Name);
         if ($Page) {
            if ($Page > 1 || Gdn::Session()->UserID)
               $Result .= '/p'.$Page;
         }
         return Url($Result, $WithDomain);
      }
      

    Now you have discussion URLs of the form http://forums.example.com/d/discussion-name-no-ugly-ids. You just need to repeat this process for any other controller you want to prettify.

    EDIT - If it is not obvious, I think this is a bad idea. That said, we have different requirements. :)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.