Why You Should Avoid Dynamic URLs
Tags: apache, php, seo, socialmedia
Published: 2024-01-19 20:56:40

[SEO](https://en.wikipedia.org/wiki/Search_engine_optimization)\-friendly URLs 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](https://www.techopedia.com/definition/27229/static-url) are not dynamically generated and do not accept [string parameters](https://en.wikipedia.org/wiki/Query_string)**. 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 URL**](https://www.techopedia.com/definition/1198/dynamic-url)**s contain a** [**query string**](https://en.wikipedia.org/wiki/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. The page will display 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 for 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**](https://support.google.com/google-ads/answer/2615875?hl=en). 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 there are different indexed versions, these can quickly lead to [duplicate content](https://en.ryte.com/wiki/Duplicate_Content), which is [not good in terms of SEO](https://moz.com/learn/seo/duplicate-content)

- Dynamic URLs are dirty and confusing, which results in poor [clickthrough rate](https://support.google.com/google-ads/answer/2615875?hl=en) in [search result pages](https://en.ryte.com/wiki/SERP)

- Dynamic URLs are often not described by [keywords](https://en.ryte.com/wiki/Keyword), 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](http://www.apache.org/), this can be easily achieved by **adding some specific rewrite rules to your** [**`.htaccess`**](https://httpd.apache.org/docs/current/howto/htaccess.html) **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:

```
[`Options +FollowSymLinks`](https://httpd.apache.org/docs/2.4/mod/core.html#options)
```

#### 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:

```
[`Options +FollowSymLinks`](https://httpd.apache.org/docs/2.4/mod/core.html#options)
```

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](https://webmasters.stackexchange.com/questions/86450/htaccess-rewrite-url-leads-to-missing-css), you can fix this by adding a [](https://www.w3schools.com/tags/tag_base.asp) element in the `<head>` section of your HTML document as follows:

```html
<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 on 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:

- [https://www.webconfs.com/web-tools/url-rewriting-tool/](https://www.webconfs.com/web-tools/url-rewriting-tool/): It automatically generates multiple `.htacess` files to convert a given dynamic URL into a static-looking URL.

- [https://htaccess.madewithlove.be/](https://htaccess.madewithlove.be/): It allows you to test any `.htaccess` file online without risking breaking your website.

## Conclusion

Static URLs are more SEO-friendly and shareable than dynamic URLs. For this reason, you should always avoid using the latter. Converting a static URL into a dynamic URL is easy, as I have just shown. By adding some specific rewrite rules, you can replace all your dynamic URLs with more human-readable static URLs.

Thanks for reading! I hope that you found this article helpful.
  
***
_The post "[Why You Should Avoid Dynamic URLs](https://writech.run/blog/why-you-should-avoid-dynamic-urls-f429bcf16733/)" appeared first on [Writech](https://writech.run)._