Why You Should Avoid Dynamic URLs
By: Antonello Zanini
Tags: SEO, Apache, Tutorial, PHP, Social Media

Why You Should Avoid Dynamic URLs

Photo by Caspar Camille Rubin on Unsplash

SEO-friendly URLs are designed to meet the needs of searchers and users. In a world ruled by social media, the easier a link is to remember and share, the better. An ideal URL should be short, easy to read, and easy to understand. This helps in securing a company brand. This article will look into why you should avoid dynamic URLs and how you can replace them with static-looking URLs.

Two Types of URLs

URLs can be classified into two classes: static and dynamic.

Static URLs do not accept string parameters and are not dynamically generated. This means that the only way to modify the content of such a web page is by changing the HTML code.

Examples:

https://www.mydomain.com/articles/my-first-article

https://www.mydomain.com/en/articles/1/my-first-article

Dynamic URLs contain a query string, which is a part of the URL that assigns values to specified parameters. These are passed directly to the server and used to dynamically retrieve content from a database. Content that will be displayed on the page accordingly, which will change based on the result of the query, without the need to touch the HTML code. In this case, such a web page acts just like a template for the content.

Examples:

https://www.mydomain.com/article.php?id=1

https://www.mydomain.com/articles/page.php?article_id=1&lang=en

Static vs. Dynamic URLs & SEO

Static URLs tend to obtain a better ranking in the search engine result pages. This is based on the assumption that search engines find it difficult to crawl and analyze dynamic URLs, which include parameters in them.

Plus, static URLs perform better in terms of clickthrough rate. Users can remember, understand, and read them easily and if a static URL matches the description and/or title of a website, they will likely click on it.

Another important aspect is that static URLs are easier to communicate by voice and share than dynamic URLs.

There are many other good reasons why static URLs are better for SEO than dynamic URLs. Let’s examine a few of them:

from a certain point of view, dynamic URLs are nonexistent for search engines, because they index the web by crawling it, not by filling in forms

dynamic URLs can consist of multiple parameters and if different versions get indexed, these can quickly lead to duplicate content, which is not good in terms of SEO

dynamic URLs are dirty and confusing, which brings to poor clickthrough rate in search result pages

dynamic URLs are often not described by keywords, which is not good from a semantic point of view

URL parameters make dynamic URLs longer than static URLs, and longer URLs are usually indexed more slowly than shorter ones.

Turning Dynamic URLs Into Static-Looking URLs

If your website is served by an Apache webserver, this can be easily achieved by adding some specific rewrite rules to your .htaccess file.

The parameters inside your .php files will be retrieved as usual. What you can change are all the dynamic links inside your code, which you should replace with custom generated static-looking URLs.

First of all, make sure you already have a .htaccess file in the root folder of your website, otherwise create a new one.

Example 1

Let’s say you want to turn https://www.mydomain.com/articles.php?id=1 into https://www.mydomain.com/articles/my-first-article .

To do so, add to your .htacess these lines:

Example 2

Now your goal is to convert https://www.mydomain.com/articles/page.php?article_id=1&lang=en into https://www.mydomain.com/en/articles/1/my-first-article .

To achieve such a result, you can put into your .htacess the following lines:

Please note that now the article.php page will be loaded without any JS, CSS, or images retrieved with relative URLs. This happens because they will be searched under the $1 folder, which doesn't exist. As described here, you can fix this by adding a <base> element in the <head> section of your HTML document as follows:

<base href="/articles/">

Put the path to the folder where the original .php file is placed inside the href attribute. This will be used as the base URL for all relative URLs in the page.

Bonus

Finding the working rewrite rule might be a complex task, especially for beginners. This is why I recommend the following two tools: