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.

URLs including ?p=

tcwebbertcwebber New
edited February 2019 in Vanilla 2.0 - 2.8

Can anyone help me with the problem of URLs including ?p=

Fresh install of Vanilla 2.8

I have gone through the suggestions here (and shown below): https://docs.vanillaforums.com/developer/installation/self-hosting/#from-vanilla-2-3-or-earlier

If your forum still uses URLs including ?p=, support for this URL structure has ended. Follow these steps to switch to the simpler format:

  1. Confirm your server is setup to handle rewrites. On Apache, using the .htaccess file provided will accomplish this. Additional setup is required on nginx and other platforms.
  2. Test whether it is working by visiting /discussions - if you see a discussions list (rather than a 404), it is likely setup correctly.
  3. Open /conf/config.php and find the line with $Configuration['Garden']['RewriteUrls'] = false;and delete the entire line.

Your site should immediately switch to “pretty” URL paths instead of using the ‘p’ parameter. If there is a problem, re-add the line to your config and do further troubleshooting.

None of those helped. The forum url is https://treecrops.org.nz/forum/

Comments

  • Are you on Apache or other?

    If Apache, post your htaccess file contents here

  • tcwebbertcwebber New
    edited February 2019

    Thanks @donshakespeare htaccess file contents:


    AddHandler application/x-httpd-php73 .php .php5 .php4 .php3

    AuthName "forum"

    AuthUserFile "/home/treecrop/.htpasswds/public_html/forum/passwd"


    # Modified

    # If you modify this file then change the above line to: # Modified


    <IfModule mod_rewrite.c>

      RewriteEngine On


      ####

      # Certain hosts may require the following line.

      # If vanilla is in a subfolder then you need to specify it after the /.

      # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)

      ####

      #RewriteBase /forum


      # Make sure that / doesn't try to go to index.php without a rewrite :)

      DirectoryIndex disabled


      ####

      # Deny access to certain directories that SHOULD NOT be exposed.

      ####

      RewriteRule (^|/)\.git - [L,R=403]

      RewriteRule ^cache/ - [L,R=403]

      RewriteRule ^cgi-bin/ - [L,R=403]

      RewriteRule ^uploads/import/ - [L,R=403]

      RewriteRule ^vendor/ - [L,R=403]


      ####

      # Prevent access to any php script by redirecting the request to /index.php

      # You can add an exception by adding another RewriteCond after this one.

      # Example: RewriteCond %{REQUEST_URI} !^/yourscriptname.php$

      # You can comment out this section if it causes you problems.

      # This is just a nice to have for security purposes.

      ####

      RewriteCond %{REQUEST_URI} !/index.php$

      RewriteRule (.+\.php) [E=X_REWRITE:1,E=X_PATH_INFO:/$1,L]


      ####

      # Redirect any non existing file/directory to /index.php

      ####

      RewriteCond %{REQUEST_FILENAME} !-f

      RewriteRule (.*) index.php [E=X_REWRITE:1,E=X_PATH_INFO:/$1,L]


      ####

      # Add the proper X_REWRITE server variable for rewritten requests.

      ####

      RewriteCond %{ENV:REDIRECT_X_REWRITE} .+

      RewriteCond %{ENV:REDIRECT_X_PATH_INFO} (.+)

      RewriteRule ^index\.php - [E=X_REWRITE:1,E=!REDIRECT_X_REWRITE,E=X_PATH_INFO:%1,E=!REDIRECT_X_PATH_INFO,L]

    </IfModule>


    <IfModule mod_headers.c>

      <FilesMatch "(?<!embed)\.(css|js|woff|ttf|eot|svg|png|gif|jpeg|jpg|ico|swf)$">

       Header set Cache-Control "max-age=315360000"

       Header set Expires "31 December 2037 23:59:59 GMT"

      </FilesMatch>

    </IfModule>

  • R_JR_J Ex-Fanboy Munich Admin

    There is one error in your file: the RewriteBase is still commented. You have to remove the # sign:


    # Modified
    # If you modify this file then change the above line to: # Modified
    
    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      ####
      # Certain hosts may require the following line.
      # If vanilla is in a subfolder then you need to specify it after the /.
      # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
      ####
      RewriteBase /forum
    
      # Make sure that / doesn't try to go to index.php without a rewrite :)
      DirectoryIndex disabled
    
      ####
      # Deny access to certain directories that SHOULD NOT be exposed.
      ####
      RewriteRule (^|/)\.git - [L,R=403]
      RewriteRule ^cache/ - [L,R=403]
      RewriteRule ^cgi-bin/ - [L,R=403]
      RewriteRule ^uploads/import/ - [L,R=403]
      RewriteRule ^vendor/ - [L,R=403]
    
      ####
      # Prevent access to any php script by redirecting the request to /index.php
      # You can add an exception by adding another RewriteCond after this one.
      # Example: RewriteCond %{REQUEST_URI} !^/yourscriptname.php$
      # You can comment out this section if it causes you problems.
      # This is just a nice to have for security purposes.
      ####
      RewriteCond %{REQUEST_URI} !/index.php$
      RewriteRule (.+\.php) [E=X_REWRITE:1,E=X_PATH_INFO:/$1,L]
    
      ####
      # Redirect any non existing file/directory to /index.php
      ####
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule (.*) index.php [E=X_REWRITE:1,E=X_PATH_INFO:/$1,L]
    
      ####
      # Add the proper X_REWRITE server variable for rewritten requests.
      ####
      RewriteCond %{ENV:REDIRECT_X_REWRITE} .+
      RewriteCond %{ENV:REDIRECT_X_PATH_INFO} (.+)
      RewriteRule ^index\.php - [E=X_REWRITE:1,E=!REDIRECT_X_REWRITE,E=X_PATH_INFO:%1,E=!REDIRECT_X_PATH_INFO,L]
    </IfModule>
    
    <IfModule mod_headers.c>
      <FilesMatch "(?<!embed)\.(css|js|woff|ttf|eot|svg|png|gif|jpeg|jpg|ico|swf)$">
       Header set Cache-Control "max-age=315360000"
       Header set Expires "31 December 2037 23:59:59 GMT"
      </FilesMatch>
    </IfModule> 
    


    But the current htaccess file sadfully doesn't work for everyone. If the above still brings no luck try this one instead:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        # Certain hosts may require the following line.
        # If vanilla is in a subfolder then you need to specify it after the /.
        # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
        RewriteBase /forum
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
    </IfModule>
    


    But before you have used that .htaccess file, there already has been an existing one, at least that's what you have said in another post. Please post the content of that one. I assume your forum will not work without the original content being combined with the new htaccess file.

  • @R_J THANK YOU!! your second suggestion worked. I am still getting ?p= included in URLs: https://treecrops.org.nz/forum/index.php?p=/discussion/5/test

    But my original problem of the rich editor box disappearing has been solved.

    Will it be a problem that ?p= is still included in URLs, or can I ignore that?

    Regarding the existing .htaccess file, I added the content of the htaccess.dist file to that existing file. All that was in the existing file was:

    AddHandler application/x-httpd-php73 .php .php5 .php4 .php3

    AuthName "forum"

    AuthUserFile "/home/treecrop/.htpasswds/public_html/forum/passwd"


    Should I delete the htaccess.dist file now?

  • htaccess.dist is a file with invalid file extension, so it does no harm sitting where it is, as it is not been used.


    On the other hand, it is a problem that your forum is still not rewriting to "pretty" urls.

    Ask your webhost to ensure that your rewrite module is activated

    Also, is this the valid path on your server?

    /home/treecrop/public_html/forum/

    Is there any .htaccess file up one folder level in ...?

    /home/treecrop/public_html

  • R_JR_J Ex-Fanboy Munich Admin

    Just add $Configuration['Garden']['RewriteUrls'] = true; to your /conf/config.php and everything will work as expected

  • For some reason I have never had to add that setting

  • R_JR_J Ex-Fanboy Munich Admin

    @donshakespeare That's the default config by now, that's why you haven't to add it. But read his first post: he has deleted that line 😉

  • Thanks @R_J that worked. That line was not in the original htaccess.dist file that I uploaded with my install - I thought it was weird that the above instructions said:

    Open /conf/config.php and find the line with $Configuration['Garden']['RewriteUrls'] = false;and delete the entire line.

    That line was never there.

    Now I have a new problem: on the home page https://treecrops.org.nz/forum/ the number of discussions and comments doesn't show up for each category, even though I've made several test posts in each. Should I post this in a new discussion?


  • R_JR_J Ex-Fanboy Munich Admin
  • Thank you. All good now 😁

  • Sorry to reopen this thread but I followed the steps listed in the docs and I still get *?p=* too in the forum. Not having pretty indexable forum urls doesn't bother me, but this is messing with the twitter account login which is a bit annoying.

    The strange thing is that if I visit https://forum.mydomain.com and open a discussion I get ?p= but if instead of opening a discussion I go to https://forum.mydomain.com/discussions and carry on from there, the ?p= does not appear as I browse through the forum.

    I have added the explicit line to do the redirects and set it to true.

    Is there anything that could cause an odd behavior like this?

    My forum is in a mydomain.com/forums subdirectory, but I am accessing it through a subdomain (forum.mydomain.com) so I'm a bit unsure about what that might entail when it comes to adjusting the RewriteBase in the .htaccess file, for now I've left it as it is (/)

  • whu606whu606 I'm not a SuperHero; I just like wearing tights... MVP
    edited March 2019

    @forgerapp

    Welcome to the community.

    Well, assuming you are using Apache as your webserver, you need to remove the # from the line

    #RewriteBase /
    

    and make it

    RewriteBase /forums
    
  • Thanks for your quick reply! Unfortunately I just tried it, and it seems that if I do this the forum stops working and I get internal server error messages as I browse through it.

    My issue is the following, the forum is under https://mydomain.com/forums, but I want/must access it through: https://forum.mydomain.com, this subdomain points to the "/forums" folder which is what's confusing the whole thing, if I understand well the RedirectBase shouldn't be needed as the redirection has been done prior to this, my issue is that I don't know how I could get it to work given that I want to access the forum through the subdomain-based address, and not the subdirectory-based one if that makes sense.

  • @forgerapp You are talking server stuff. You need to tell your host to create a subdomain for you. As you are describing, this has to do with some sort of shared virtual hosting, where a domain (in your case, subdomain) does not have its own dedicated file system.

    Once your host has sorted out your issue, yes the RedirectBase should point to the root "/" and not "/forums, well unless ya want https://forum.mydomain.com/forums which I doubt :)

  • Hi, thanks for your reply, I do have the subdomain in place and working, the forum works too, the different logins work too, my issue is that when I go to my:

    https://forum.mydomain.com and click on a discussion, I get ?p= as part of the url, on the other hand, if I go to https://forum.mydomain.com/discussions and click on any discussion, I get the "clean" urls with no strange query parameter. I would like to have the same behavior I get when I go to /discussions, but when users type in the "root" url (the subdomain one)

    I'm not quite sure about how to get those ?p= to disappear, for now I'm linking to /discussions but I'd really prefer to keep it short.

    I only mentioned the subfolder and the subdomain since I wasn't sure about the RedirectBase, but after a quick test I noticed that adding the additional subfolder made hell break loose so I reverted it.

  • @forgerapp, sounds like your .htaccess file isn't passing the X_REWRITE server variable when the URL is the root of the site. It could be that one of the RewriteRules don't work well on subdomains.

    Add Pages to Vanilla with the Basic Pages app

Sign In or Register to comment.