Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Friendly Urls

24

Comments

  • Hi Stuart, From what I understand (and from messing around with my install) the orginal URLs will still work. What mod_rewite does is when it gets a request to http://forum.mydomain.com/categories/ it tells the server to execute to code located at http://forum.mydomain.com/categories.php and keeps the URL in the browser the same (rather than a straight redirect where to URL in the browser changes). Over a period of time as you forum is re-crawled you will see the old style URLs disappear from your listings (this is what I understand will happen at least). HTH Neil
  • There's a problem I experienced using the "Poll"-Extension by Jazzman but that could possibly affect other extensions as well when Friendy Urls is activated:

    The Poll-Extension, when a poll is added to a discussion, inserts a <form%gt; to... vote.
    Yeah, but that's not working with Friendly Urls enabled, because the form is started via
    $this->Get_PostBackForm('frmVote')

    This very method in Framework.Class.Control.php reads:
    function Get_PostBackForm($FormID = '', $PostBackMethod = 'post', $TargetUrl = '', $EncType = '', $TargetFrame = '') { $TargetUrl = ForceString($TargetUrl, $this->Context->SelfUrl); if ($FormID != '') $FormID = ' id="'.$FormID.'"'; return '<form'.$FormID.' method="'.$PostBackMethod.'" action="'.GetUrl($this->Context->Configuration, $TargetUrl).'"'.($EncType != '' ? ' enctype="'.$EncType.'"' : '').($TargetFrame != '' ? ' target="'.$TargetFrame.'"' : '').'>' .$this->PostBackParams->GetHiddenInputs(); }

    As you can see, the $TargetUrl parameter is left to default which means the following line in Get_PostBackForm is executed:
    $TargetUrl = ForceString($TargetUrl, $this->Context->SelfUrl);

    In a discussion, this normally sets the target variable to comments.php which is, because Friendly Urls is activated, /discussion/ (slashes added to show it's a directory, that's not contained in the exact value if I remember correctly). So the form will read:
    <form id="frmVote" action="http://vanilla.art-fx.org/discussion/" method="post">

    Well, /discussion/ isn't accepted: this delivers a 404 error. What's missing? The discussion's ID and the url-slug of the discussion's title: /discussion/31/some-title.

    I don't know whether this extension is the right place to mention that point, but as you, Mark, are programming Vanilla and this extension both yourself I hope that's no problem :)

    Please fix this issue as soon as possible, making your Get_PostBackForm method work as it's intended so one can enable Friendly Urls and Poll.
  • Oh, there was yet another thing: extensions that might need the DiscussionID parameter weren't redirected at all, so I added the following rule to your .htaccess file:
    RewriteRule ^extension/([0-9]+)/?(.*)$ extension.php?DiscussionID=$1&$2 [QSA,L]

    The Poll extension (yeah, again :)) needs this to make Add Poll to Discussion working. I think the way it's redirected ($2 for optional parameters) is generic enough, but probably rules like the following are needed as well:
    RewriteRule ^extension/([0-9]+)/$ extension.php?DiscussionID=$1 [QSA,L] RewriteRule ^extension/([0-9]+)$ extension.php?DiscussionID=$1 [QSA,L]
  • DivineDominion,
    Dinoboff's .htaccess is a good workaround for all of the Poll issues you're talking about.

    http://lussumo.com/community/discussion/2803/

    The Poll extension really needs to be tweaked a bit. For instance, you can fix the $TargetUrl issue on comment.php pages by making the following edits to the Poll add on:

    Change Line 6 of /extensions/Poll/templates/poll_vote.php to be this:
    '.$this->Get_PostBackForm('frmVote', 'post', 'voteform.php').'
    ...And then add the following below Line 6 of /extensions/Poll/conf/settings.php:
    $Context->Configuration['REWRITE_voteform.php'] = 'comments.php';

    ...but doing that screws up the Poll in the Panel of the index.php pages. So, to get Polls to work on index pages you have make the Poll on index pages call an unedited/original version of templates/poll_vote.php. So essentially you create two templates, one for the index.php pages and one for the comments.php and have the Panel vote form call the original version.

    But, the easiest thing to do is to just use Dinoboff's .htaccess for a quick fix.
  • Hello neilroberts, It is not good that the orginal URLs will still work. It needs a complete redirect so when someone type the old URL it gets redirected to the new one. Search engines crawld the old one and they need to be redirected to the new ones otherwise you get the duplicate. How can we do a complete 301 redirect with the Dinoboof htaccess ??
  • Does anyone else have this AddOn installed with the 'Who's Online' extension? I am experiencing a problem with viewing a user's account while already in a discussion. When I am viewing a Discussion and then click on someone's username under the 'Who's Online' box, it should take me to their user account but it doesn't. I am just sent right back to the conversation I'm viewing, but with a different URL at the top now. For example, I am viewing the page: http://www.fngeeks.net/vanilla/discussion/18/welcome/#Item_17 I then click on my username 'Gabe' under 'Who's Online' which has the HREF set to: http://www.fngeeks.net/vanilla/discussion/18/welcome/account.php?u=2 and end up viewing the same Discussion instead of being taken to my user account info. I have a feeling this is a problem with the .htaccess file and the RewriteRule (or lack thereof). Unfortunately I am not very good with mod_rewrite and don't understand the file that well. The contents of my .htaccess file are as follows: RewriteEngine On Options +FollowSymLinks -Multiviews #Discussions RewriteRule ^discussions$ index.php [QSA,L] RewriteRule ^discussions/$ index.php [QSA,L] RewriteRule ^discussions/([0-9]+)$ index.php?page=$1 [QSA,L] RewriteRule ^discussions/([0-9]+)/$ index.php?page=$1 [QSA,L] RewriteRule ^([0-9]+)$ index.php?CategoryID=$1 [QSA,L] RewriteRule ^([0-9]+)/$ index.php?CategoryID=$1 [QSA,L] RewriteRule ^([0-9]+)/([0-9]+)$ index.php?CategoryID=$1&page=$2 [QSA,L] RewriteRule ^([0-9]+)/([0-9]+)/$ index.php?CategoryID=$1&page=$2 [QSA,L] #Comments RewriteRule ^discussion/([0-9]+)/([0-9]+)/(.*)$ comments.php?DiscussionID=$1&page=$2 [QSA,L] RewriteRule ^discussion/([0-9]+)/([0-9]+)/(.*)/$ comments.php?DiscussionID=$1&page=$2 [QSA,L] RewriteRule ^discussion/([0-9]+)/(.*)$ comments.php?DiscussionID=$1 [QSA,L] RewriteRule ^discussion/([0-9]+)/(.*)/$ comments.php?DiscussionID=$1 [QSA,L] RewriteRule ^discussion/([0-9]+)/([0-9]+)$ comments.php?DiscussionID=$1&page=$2 [QSA,L] RewriteRule ^discussion/([0-9]+)/([0-9]+)/$ comments.php?DiscussionID=$1&page=$2 [QSA,L] RewriteRule ^discussion/([0-9]+)$ comments.php?DiscussionID=$1 [QSA,L] RewriteRule ^discussion/([0-9]+)/$ comments.php?DiscussionID=$1 [QSA,L] #Categories RewriteRule ^categories/$ categories.php [QSA,L] #Account RewriteRule ^account/$ account.php [QSA,L] RewriteRule ^account/([0-9]+)$ account.php?u=$1 [QSA,L] RewriteRule ^account/([0-9]+)/$ account.php?u=$1 [QSA,L] #Search RewriteRule ^search/$ search.php [QSA,L] RewriteRule ^search/([0-9]+)$ search.php?page=$1 [QSA,L] RewriteRule ^search/([0-9]+)/$ search.php?page=$1 [QSA,L] RewriteRule ^search/saved/([0-9]+)$ search.php?SearchID=$1 [QSA,L] RewriteRule ^search/saved/([0-9]+)/$ search.php?SearchID=$1 [QSA,L] RewriteRule ^search/saved/([0-9]+)/([0-9]+)$ search.php?SearchID=$1&page=$2 [QSA,L] RewriteRule ^search/saved/([0-9]+)/([0-9]+)/$ search.php?SearchID=$1&page=$2 [QSA,L] #Post RewriteRule ^post/$ post.php [QSA,L] RewriteRule ^post/([0-9]+)$ post.php?CommentID=$1 [QSA,L] RewriteRule ^post/([0-9]+)/$ post.php?CommentID=$1 [QSA,L] RewriteRule ^post/category/([0-9]+)$ post.php?CategoryID=$1 [QSA,L] RewriteRule ^post/category/([0-9]+)/$ post.php?CategoryID=$1 [QSA,L] #Settings RewriteRule ^settings/$ settings.php [QSA,L] #People RewriteRule ^people/$ people.php [QSA,L] #extension RewriteRule ^extension/$ extension.php [QSA,L] # Prevent some little bad effects of Friendly Urls on relative links in some # extensions RewriteRule ^(discussions|categories|search|post|settings|people|[0-9]+)/(extensions|themes|images|ajax)/(.*) $2/$3 [QSA,L] RewriteRule ^(discussions|categories|search|post|settings|people|[0-9]+)/(account.php|categories.php|comments.php|extension.php|index.php|people.php|post.php|search.php|settings.php) $2 [QSA,L] RewriteRule ^discussion/([0-9]+/){1,2}[^/]*/(extensions|themes|images|ajax)/(.*) $2/$3 [QSA,L] RewriteRule ^discussion/([0-9]+/){1,2}[^/]*/(account.php|categories.php|comments.php|extension.php|index.php|people.php|post.php|search.php|settings.php) $2 [QSA,L] RewriteRule ^(discussions|account|search|post|[0-9]+)/.+/(extensions|themes|images|ajax)/(.*) $2/$3 [QSA,L] RewriteRule ^(discussions|account|search|post|[0-9]+)/.+/(account.php|categories.php|comments.php|extension.php|index.php|people.php|post.php|search.php|settings.php) $2 [QSA,L] #Pages RewriteRule ^page/(.*)$ index.php?Page=$1 [QSA,L]
  • Nevermind. I was able to fix the problem by rewriting a line in the Who's Online extension.
  • Anyone got this working? lol

    Just tried it out now, changing round some stuff in the htaccess such as /categories/ to /cat/ and so on... but the actual URL retains /categories/ ... any reason? :S
  • Nevermind. I was able to fix the problem by rewriting a line in the Who's Online extension.

    Care to tell us what you changed gpreston? It could help out Chris here...
  • I would guess its the same relative URL problem we saw yesterday...

    Line 163: $Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\"");
    Should be: $Url = GetUrl($Context->Configuration, 'account.php', '', 'u=', $name['UserID']); $Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), $Url, NULL, 'title="$TimePast"');

    Edit: More 'proper' use of GetUrl, thanks to finding Gprestion's fix: Who's Online # 42
  • How about:

    #Extensions RewriteRule ^extension/(.+)/(.+)/$ extension.php?PostBackAction=$1&page=$2 [QSA,L] RewriteRule ^extension/(.+)/(.+)$ extension.php?PostBackAction=$1&page=$2 [QSA,L] RewriteRule ^extension/(.+)/$ extension.php?PostBackAction=$1 [QSA,L] RewriteRule ^extension/(.+)$ extension.php?PostBackAction=$1 [QSA,L]

    Reason is me writing my extension and urls looking like: domain.tld/extension/LightGallery/Berlin/

    Howevery this probably will mess up some other extensions, but as I see it nearly none of them support friendly-urls anyway ;-)
  • Going on from this - wouldn't it be nice to have the same kind of thing for settings? That way, to change the settings for the Packer extension we would just type in /settings/Packer. The following seems to work well, but if someone who knew what they were doing could check it for fatal errors that would be great :) Of curse, then we need to get Vanilla to write the links like this (how?).

    #Settings RewriteRule ^settings/$ settings.php [QSA,L] RewriteRule ^settings/(.+)/$ settings.php?PostBackAction=$1 [QSA,L] RewriteRule ^settings/(.+)$ settings.php?PostBackAction=$1 [QSA,L]
  • Would it be possible to use this extension in such a way where rather than getting
    http://vanilladirectory.com/account/1/

    you would be able to pull the registered username and have it display
    http://vanilladirectory.com/account/resilient/
  • This "extension" should be build in into vanilla, then nice short urls would be possible. Doing it by .htaccess is completly wrong :( but what you are asking is nevertheless possible. it would require changing the account page - another extension, or adding to this
  • It is built into Vanilla. Check GetUrl() in library/Framework.Function.php.
  • Yeah, but I meant the other part. Parsing Short-Urls.
    I'm not sure myself how to do it so it will work on alle servers.
    I always use ORIG_PATH_INFO
    $arguments = explode('/', $HTTP_SERVER_VARS['ORIG_PATH_INFO']);
    However, this has nothing to do with the question above ;)
  • Resilient:
    I did that a bit back--you have to edit the theme file to build the user name on the URL instead of the ID, (theme files comments.php, account.php discussions.php and I think one for a search page) and then there is a GetUserIDByName() function somewhere...

    Will have a look.
  • When you're on a Page Manager page, because those pages have /page/ artificially inserted into the URLs, it then causes other links on those pages to have /page/ inserted into them as well. Eg /people.php to sign in/out becomes /page/people.php (resulting in an error) etc.. How can I make the Page Manager pages not have the /page/ in front of them, so pages are like www.mydomain.com/pagename/ same as the rest of the friendly URLs? Also how do I get the Contact Form extension to have a friendly URL? Thanks in advance..
  • WallPhone

    Many thanks, I appreciate your help and look forward to getting an update from you when you figure it out. :)
  • Is this supposed to make everything load slower ? Or did I do something wrong.
Sign In or Register to comment.