We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15001
    • 697 Posts
    Hello,

    Managing a website where each user has it's own webpage, powered by WebloginPE, I wonder how to make friendly URLs for those pages.

    Currenlty, all user pages share the same MODX document id, and the username parameter tells which one to display

    e.g. www.somesite.com/index.php?id=12&service=viewprofile&username=j_smith (user webpage)
    e.g. www.somesite.com/index.php?id=34&service=viewprofile&username=j_smith (contact user)

    I would like those pages to look like :

    www.somesite.com/John-Smith
    www.somesite.com/contact-John-Smith

    There is of course the possibility to set one or two permanent redirections for each user :
    Redirect permanent /John-Smith /index.php?id=12&service=viewprofile&username=j_smith


    But this would not truely be friendly url, as the URL having parameters would display in the address bar. Additionally, I believe that search engines don't like much such redirections.

    My idea is to prepend RewriteRules for the given document id before the generic rewrite rule below.

    Since there are not too many users (about 120 currently and about 5 added each year), creating one rewrite rule per user that replaces its username by it's firstname and name would not be a problem.

    Any idea how to implement this ?

    Here are the rewrite conditions and rewrite rules of the current .htacess file :

    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    [ed. note: Jul last edited this post 11 years, 4 months ago.]
    • I think you might do better to use a plugin with the onPageNotFound event and use the URL to determine which user to load into the page.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 15001
        • 697 Posts
        To give each user an access to his web page, I decided in the end to stay with permanent redirections based on regular expressions.

        The redirections are set in such a way that the page of a user named "Alexandre Dupont" (fictive name) can be accessed by any combination ending by his name, like
        domain.ext/dupont
        domain.ext/alexandre-dupont
        domain.ext/a.dupont
        a.s.o.

        RewriteRule ^(.*)dupont$ index.php?id=28&service=viewprofile&username=a_dupont [R=301,L]
        RewriteRule ^(.*)pont$ index.php?id=28&service=viewprofile&username=b_pont [R=301,L]


        Everything works fine, excepted when the family name of a user is contained inside the family name of another user. Then, the redirection that is applied is always toward the web page of the user with the shortest of the two names. In example above, the redirection is always done toward the web page of user "Pont", even when I type "domain.ext/dupont".

        I hoped that the "L" flag would stop applying redirections (as "L" stands for "Last"), but it isn't the case. I also tryied adding the "NC" flag (Non Chain), but without success. Any idea how could I stop any later redirection if the redirection for "dupont" occurs?