tutorials

WHMCS 7.8 Friendly URLs Configuration for Nginx4 min read

April 13, 2019 3 min read

author:

WHMCS 7.8 Friendly URLs Configuration for Nginx4 min read

Hi there again! If you are like me and want to use the friendly URLs option with Nginx on WHMCS, but noticed that it does not work, then you have come to the right place.

Why Add SEO Friendly URLs?

Friendly URLs both look good for the user, is easier to remember and additionally help search engines, such as Google better understand your website.

An example of a regular URL
An example of an SEO friendly URL


Add the Configuration for WHMCS in Your Default.conf file.

This tutorial is very simple and you only need to edit one file,
default.conf. By default in nginx, this file is found in: /etc/nginx/conf.d/default.conf

You can edit this file by running the following command:

nano /etc/nginx/conf.d/default.conf 

Once you have opened your configuration file, proceed towards adding the following code to the file within the server paragraphs:

    # WHMCS CONFIG
    # When WHMCS updates, make sure to get the newest configuration at https://hostup.org/blog/whmcs-friendly-urls-configuration-for-nginx/

    location ~ /billing/announcements/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/announcements/$1;
    }

    location ~ /billing/download/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/download$1;
    }

    location ~ /billing/knowledgebase/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/knowledgebase/$1;
    }

    location ~ /billing/store/ssl-certificates/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/store/ssl-certificates/$1;
    }

    location ~ /billing/store/sitelock/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/store/sitelock/$1;
    }

    location ~ /billing/store/website-builder/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/store/website-builder/$1;
    }

    location ~ /billing/store/order/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/store/order/$1;
    }

    location ~ /billing/cart/domain/renew/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/cart/domain/renew$1;
    }

    location ~ /billing/account/paymentmethods/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/account/paymentmethods$1;
    }

    location ~ /billing/password/reset/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/password/reset/$1;
    }

    location ~ /billing/account/security/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/account/security$1;
    }

    location ~ /billing/subscription?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=/subscription$1;
    }

#Social media authorization
    location ~ /billing/auth/provider/google_signin/finalize/?(.*)$ {
        rewrite ^/(.*)$ /billing/index.php?rp=auth/provider/google_signin/finalize$1;
    }

 #WHMCS ADMIN
location ~ /billing/admin/(addons|apps|search|domains|help\/license|services|setup|utilities\/system\/php-compat)(.*) {
        rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/$1$2 last; 
    }

    location ~ /billing/admin/client/?(.*)/paymethods/?(.*)$ {
        rewrite ^/(.*)$ /billing/admin/index.php?rp=/client/?(.*)/paymethods/$1;
    }

    location ~ /billing/admin/setup/auth/?(.*)$ {
        rewrite ^/(.*)$ /billing/admin/index.php?rp=/setup/auth/$1;
    }

    location ~ /billing/admin/client/?(.*)/tickets/?(.*)$ {
        rewrite ^/(.*)$ /billing/admin/index.php?rp=/client/?(.*)/tickets/$1;
    }

    location ~ /billing/admin/client/?(.*)/invoice/?(.*)/capture/?(.*)$ {
        rewrite ^/(.*)$ /billing/admin/index.php?rp=/client/?(.*)/invoice/?(.*)/capture/$1;
    }

    location ~ /billing/admin/account/security/two-factor/?(.*)$ {
        rewrite ^/(.*)$ /billing/admin/index.php?rp=/admin/account/security/two-factor/$1;
    }

    location ~ /billing/admin/search/intellisearch?(.*)$ {
        rewrite ^/(.*)$ /billing/admin/index.php?rp=/search/intellisearch/$1;
    }

# Security Advisory 2020-01-28
    location ^~ /vendor/ {
        deny all;
        return 403;
    }
# END WHMCS CONFIG

Save & exit by pressing CTRL + X followed by Y

Directory other than /billing

Alternatively, if you are using another directory, then this code will not work. You will have to replace ‘/billing/’ with your directory.

Here comes an example of this. Let’s say that we have our whmcs installed at another directory. For example, example.com/account. You then need to replace all of the bits of code in a similar mattar

location ~ /account/announcements/?(.*)$ {
    rewrite ^/(.*)$ /account/index.php?rp=/announcements/$1;
}

If you are instead using a subdomain, billing.example.com you can simply remove the /billing/ as shown below

location ~ /announcements/?(.*)$ {
    rewrite ^/(.*)$ /index.php?rp=/announcements/$1;
}

Directory other than /admin

If you have customized your admin directory – a security change that makes it harder for bots and other malicious users to find your login directory, then you need to make some changes to the above code.

You need to replace /admin/ with your /customdirectory/. You should follow this principle for all /admin/ as shown below.

location ~ /billing/customdirectory/setup/auth/?(.*)$ {
    rewrite ^/(.*)$ /billing/customdirectory/index.php?rp=/setup/auth/$1;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments