Apache
  • 20 Jun 2024
  • 2 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Apache

  • Dark
    Light
  • PDF

Article summary

This page will guide you through integrating Prerender with your Apache webserver, which can help improve your website's SEO.

View source on GitHub.

You can find the Apache config here.

Video guide:

Prerender token

The location of the Prerender token has changed. You can find it under the Security and Access menu under Prerender Token.

You can find the required codes in the section of the text guide below.

Text guide:

  1. Enable the required modules.
    1. In Ubuntu and other Debian based systems you might need to use the commands below:
             sudo a2enmod headers
             sudo a2enmod proxy
             sudo a2enmod proxy_http
             sudo a2enmod ssl
             sudo a2enmod rewrite
      
      Some modules might be already enabled however if a new module is enabled its recommended to restart Apache. (You can usually do that with either the service apache2 restart command)
    2. In other systems you will need to uncomment or add these lines to the webserver's config file in httpd.conf.
               LoadModule headers_module libexec/apache2/mod_headers.so
               LoadModule proxy_module libexec/apache2/mod_proxy.so
               LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
               LoadModule ssl_module libexec/apache2/mod_ssl.so
               LoadModule rewrite_module libexec/apache2/mod_rewrite.so
      
  2. Add the following lines at the bottom of your site's Apache vhost config in the 443 block.
    It's recommended ot make a backup from the file first.
                       # Prerender.io configuration

                       # Allow proxying over https
                       SSLProxyEngine on

                       # These two commands ignore the validity of the SSL Certificate of the Prerender server
                       # Only uncomment the two SSLProxy lines if you are testing with a local prerender server over       https with a self-signed cert
                       # A hosted Prerender server should have a valid SSL Certificate so the next two lines can stay commented in production
                       #SSLProxyCheckPeerName off
                       #SSLProxyVerify none
  1. Add the following lines at the top of your .htaccess file. Which is usually located in your site's root directory. It's recommended ot make a backup from the file first.

                        # Change YOUR_TOKEN to your prerender token
                        # Change https://service.prerender.io/ (at the end of the last RewriteRule)
                        # to http://localhost:3000/ when testing with a local prerender server
    
                        <IfModule mod_headers.c>
                            RequestHeader set X-Prerender-Token "YOUR_TOKEN"
                            RequestHeader set X-Prerender-Version "prerender-apache@2.0.0"
                        </IfModule>
    
                        <IfModule mod_rewrite.c>
                            RewriteEngine On
    
                            <IfModule mod_proxy_http.c>
                                RewriteCond %{HTTP_USER_AGENT} googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp|redditbot|applebot|flipboard|tumblr|bitlybot|skypeuripreview|nuzzel|discordbot|google\ page\ speed|qwantify|bitrix\ link\ preview|xing-contenttabreceiver|google-inspectiontool|chrome-lighthouse|telegrambot [NC,OR]
                                RewriteCond %{QUERY_STRING} _escaped_fragment_
                                RewriteCond %{REQUEST_URI} ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff|\.svg))
    
                                RewriteRule ^(index\.html|index\.php)?(.*) https://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}$2 [P,END]
                            </IfModule>
                        </IfModule>
    
  2. Add your Prerender token. Make sure to replace the YOUR_TOKEN place holder with your Prerender.io Token from the Security and Access menu.

  3. Restart Apache so that the config changes can take effect.
    You can do that usually with either service apache2 restart or with service httpd restart

  4. Check if the integration was successful, based on this guide.


Was this article helpful?