Announcement

Collapse
No announcement yet.

About .htaccess

Collapse
X
Collapse
  •  

  • About .htaccess

    .htaccess is a configuration file for the Apache Web Server. It allows you to customize how your server works. Depending on how your hosting provider has the server configured, you can redirect people to different locations, secure directories and files, tell browsers how long to cache files, update PHP variables, and more. vBulletin comes with a pretty extensive .htaccess file that does a these things for you.

    Location

    vBulletin comes with a file named htaccess.txt in the original download. When you install the software for the first time, you renamed this file .htaccess. It resides in your vbulletin root directory. This is the file referenced in this document.

    When you upgrade your vBulletin, the new htaccess.txt will not overwrite any changes because of the filename change.

    Comments

    Lines that begin with a 'number sign' or hashmark signifies a comment within .htaccess. Removing this leading symbol will cause the Apache webserver to process the line as a directive.

    Lines that read in simple English should remain commented out.

    Rewrites or Redirection

    The most common change that you'll most likely make in your .htacces file are additions or changes to how rewrites or redirected rules behave. Below are some basic changes people may want to make.

    Terms:

    • RewriteBase - Rewrite rules and conditions are inherited from parent directories. This tells the server to forget inheritance and start over with the rules and conditions in the specified directory.
    • RewriteCond - Basically an IF test on the URL the browser requests. If this tests to true, then then the RewriteRule will be applied.
    • RewriteRule - The changes to the requested URL applied after any conditions are met.
    • 301 Redirect [R=301] - This tells the server to return a 301 - Permanently Moved header back to the client. This is important for search engines to update their rankings over time.

    Override .htaccess in Parent Directories

    Sometimes, it is necessary to override the rewrite directives of a parent directory. An example would be if you have a copy of WordPress in the root of your website and want to install vBulletin within a sub-directory. The control to do this would be to set the RewriteBase directive at the top of your vBulletin .htaccess file. The file includes this code but it is commented out.

     # In some cases where you have other mod_rewrite rules, you may need to remove the
    # comment on the following RewriteBase line and change it to match your folder name.
    # This resets the other mod_rewrite rules for just this directory
    # If your site was www.example.com/forum, the setting would be /forum/
    #RewriteBase /
    

    Comment the line with #RewriteBase / and follow the instructions above it.

    Handle vBulletin 4 'Friendly URLs'

    Find this block of code in your .htaccess file and uncomment the necessary lines:

     #If you used friendly urls in vB4, then uncommenting the following rules will redirect the #
    #old vB4 urls to a similar location in vB5. This is unnecesary for a new vB5 install.
    rewriterule ^threads/.* showthread.php [QSA]
    rewriterule ^forums/.* forumdisplay.php [QSA]
    rewriterule ^members/.* member.php [QSA]
    rewriterule ^blogs/.* blog.php [QSA]
    rewriterule ^entries/.* entry.php [QSA]
    

    Redirect to HTTPS

    It is recommended that you use a security certificate with your site. This tells the browser to encrypt any data sent by it to the server. It also includes a key so the encryption is unique to your server. When the server receives the packet, it will automatically decrypt it in the background. This process keeps data from your users safer.

    This is another block included in the default .htaccess file. You merely have to uncomment the directives.

     to redirect users to the secure version of your site, uncomment the lines below
    #RewriteCond %{HTTPS} !=on
    rewriterule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    

    If this change doesn't work on your server, you will need to contact your hosting provider.

    Other Redirects

    Sometimes, you need to add additional redirects. It could be that your site ran under a different domain in the past or you have reconfigured your web site to use sub-domains instead of directories. These redirects will come in handy.

    Redirect non-www to www (or other subdomain)

    RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    

    Redirect www (or other subdomain) to Top Level Domain

    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L]
    

    If you're using a security certificate, it is recommended to change the destination in the Rewrite Rule lines to https and place this directive above the redirect to HTTP already in the .htaccess file. This will help reduce the number of redirects.

    Addhandler

    This directive does not exist in the default htaccess.txt file. However, on shared hosting you may see an "AddHandler" directive at the bottom of the your .htaccess. This is commonly added to specify a specific version of PHP to be used with that directory and is very common on cPanel driven sites that support many versions of PHP

    It will look like this: AddHandler application/x-httpd-php8 .php

    If this exists in your .htaccess, it is very important to leave it there. It is not generally malware or some sort of exploit. If you are concerned about an AddHandler directive, contact your hosting provider.

    Set PHP Variables

    On some servers, you can set PHP Variables within the .htaccess file. This can be useful if you do not have access to a php.ini file to edit. To do this, you would add one variable per line in the format of: php_value <key> <val>

    • key is the variable you want to change.
    • val is the value you want to set.

    Example: php_value memory_limit 1024M

    Other directives

    mod_deflate

    This tells the server to look at the file type and if it is being sent to the browser, gzip it first. The browser will automatically unzip the files before displaying them. This will reduce bandwidth.

    mod_expires

    This tells the browser to cache the files for a specific period of time. Usually two weeks for static files including images, fonts, javascript, and CSS.

    mod_headers

    vBulletin uses this directive for the same purpose as mod_expires but can be used for different purposes as well. This is just a failsafe in case the server does not have mod_expires installed.

    files_match

    This is used to prevent the download of specific files that can contain sensitive data on your server. Generally this is used as a failsafe if you leave a database backup in an inappropriate directory within a vBulletin install.

      Posting comments is disabled.

    About the Author

    Collapse

    Wayne Luke A curious juxtaposition of nature, technology and sustainability. Find out more about Wayne Luke

    Article Tags

    Collapse

    Latest Articles

    Collapse

    • About .htaccess
      by Wayne Luke
      .htaccess is a configuration file for the Apache Web Server. It allows you to customize how your server works. Depending on how your hosting provider has the server configured, you can redirect people to different locations, secure directories and files, tell browsers how long to cache files, update PHP variables, and more. vBulletin comes with a pretty extensive .htaccess file that does a these things for you. Location vBulletin comes with a file named htaccess.txt in the original download. When ...
      Mon 11 Sep '23, 11:57am
    • Answered Topics
      by Mark.B
      In vBulletin 5.6.5, we added a new feature - Answered Topics.

      Topics can now be marked as "Answered." This is a special status applied to a specific post within the topic. The post that is marked as the Answer will be highlighted and show directly under the starting post in the topic.

      The ability to mark posts as the Answer in a topic is controlled by permissions. There are three different permissions to control this.
      Usergroup and Channel Permissions both...
      Sun 8 Jan '23, 11:43am
    • Custom Node Fields
      by Mark.B


      In 5.7.2, we have added a new feature - Custom Node fields.

      This new feature allows Administrators to define text and text area fields that are assigned to channels (eg forums).
      When a user creates a new topic, defined custom node fields will be available.
      1. The Administrator will create Field Categories in the AdminCP. Each category is assigned to one or more channels.
      2. Within each category, the Administrator can create one or more fields that will get assigned
      ...
      Thu 29 Dec '22, 2:19am
    • Using User Ranks
      by Wayne Luke

      User ranks allow the administrator to set up image and HTML rewards for their users once they reach specific goals. In versions before vBulletin Connect 5.7.1, ranks could only be triggered by the number of posts and the usergroups assigned to the user. In vBulletin Connect 5.7.1, User Ranks have been expanded to allow more flexibility in creating individual ranks. Now you can build combinations of different criteria to create unique ranks for your site.

      ​ Ranks can be created using th...
      Tue 25 Oct '22, 12:04pm
    • Excluding Custom Files from Suspect File Diagnostic
      by Wayne Luke
      If you have custom files, you can create an md5 sums for your smilie directory if you want. Inside the /do_not_upload folder of your download package is a checksum sub-folder. That will create custom md5_sums files.
      1. Copy the included sample_checksum_config.php file to smilies_config.php.
      2. Enter in your forum root.
      3. Give it a product id like 'smilies'.
      4. Delete the existing directories and files in the scanpaths.
      5. Add in '/core/images/smilies', under the directories comment.
      6. Run the command
      ...
      Mon 24 Aug '20, 8:48am
    • Including Custom PHP in Modules.
      by Wayne Luke
      We've created a new package that is intended to facilitate the replacement of custom PHP modules with custom Display Template modules. It also demonstrates how to create custom API functions in general. You will find this package attached below. Steps to replace a PHP module Module Edit the api/main.php file Find the customWidgetHtml function Copy your php code from the module into the function. Change the code to generate a string value instead of echoing content and set that to the $myhtml par...
      Mon 10 Aug '20, 2:05pm
    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎