Skip to main content
add flag to rewrite rule
Source Link
Stephen Ostermiller
  • 99.4k
  • 18
  • 141
  • 364

I'd recommend keeping the codes in the URL. There are some advantages to do so:

  • Codes are easy to keep static. Names of places often change over time. If the codes are there you don't have to keep records of old names and implement redirects based on old names.
  • It is easy to rewrite when the data you need for the web-app is in the URL. .htaccess is not great for lookup tables. Putting 25,000 rewrite rules into .htaccess would be a performance killer.

I'd recommend using a URL like: /IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino You would use the following rewrite rule to put the codes into the parameter and remove the slug:

RewriteRule ^/?([A-Z]+-[A-Z]+(-[A-Z]+)?).* /demo.html?code=$1 [L]

That would take any URL that has two or three abbreviations at the beginning and put them into the code parameter. That should support either your code=IT-ROM or code=IT-ROM-FCO cases you mentioned in the comments.

Then when you generate URLs on your site, put the pretty version in the hrefs:

<a href="/IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino">

You'll also need to "canonicalize" your URLs. The URL /IT-ROM-FCO/foo-bar will then show the same content. It is probably easiest to solve this by using a meta link rel canonical tag in the head of the page with the pretty URL. That will tell Google which version is your preferred URL.

<link rel="canonical" href="https://example.com/IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino">

I'd recommend keeping the codes in the URL. There are some advantages to do so:

  • Codes are easy to keep static. Names of places often change over time. If the codes are there you don't have to keep records of old names and implement redirects based on old names.
  • It is easy to rewrite when the data you need for the web-app is in the URL. .htaccess is not great for lookup tables. Putting 25,000 rewrite rules into .htaccess would be a performance killer.

I'd recommend using a URL like: /IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino You would use the following rewrite rule to put the codes into the parameter and remove the slug:

RewriteRule ^/?([A-Z]+-[A-Z]+(-[A-Z]+)?).* /demo.html?code=$1

That would take any URL that has two or three abbreviations at the beginning and put them into the code parameter. That should support either your code=IT-ROM or code=IT-ROM-FCO cases you mentioned in the comments.

Then when you generate URLs on your site, put the pretty version in the hrefs:

<a href="/IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino">

You'll also need to "canonicalize" your URLs. The URL /IT-ROM-FCO/foo-bar will then show the same content. It is probably easiest to solve this by using a meta link rel canonical tag in the head of the page with the pretty URL. That will tell Google which version is your preferred URL.

<link rel="canonical" href="https://example.com/IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino">

I'd recommend keeping the codes in the URL. There are some advantages to do so:

  • Codes are easy to keep static. Names of places often change over time. If the codes are there you don't have to keep records of old names and implement redirects based on old names.
  • It is easy to rewrite when the data you need for the web-app is in the URL. .htaccess is not great for lookup tables. Putting 25,000 rewrite rules into .htaccess would be a performance killer.

I'd recommend using a URL like: /IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino You would use the following rewrite rule to put the codes into the parameter and remove the slug:

RewriteRule ^/?([A-Z]+-[A-Z]+(-[A-Z]+)?).* /demo.html?code=$1 [L]

That would take any URL that has two or three abbreviations at the beginning and put them into the code parameter. That should support either your code=IT-ROM or code=IT-ROM-FCO cases you mentioned in the comments.

Then when you generate URLs on your site, put the pretty version in the hrefs:

<a href="/IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino">

You'll also need to "canonicalize" your URLs. The URL /IT-ROM-FCO/foo-bar will then show the same content. It is probably easiest to solve this by using a meta link rel canonical tag in the head of the page with the pretty URL. That will tell Google which version is your preferred URL.

<link rel="canonical" href="https://example.com/IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino">
Source Link
Stephen Ostermiller
  • 99.4k
  • 18
  • 141
  • 364

I'd recommend keeping the codes in the URL. There are some advantages to do so:

  • Codes are easy to keep static. Names of places often change over time. If the codes are there you don't have to keep records of old names and implement redirects based on old names.
  • It is easy to rewrite when the data you need for the web-app is in the URL. .htaccess is not great for lookup tables. Putting 25,000 rewrite rules into .htaccess would be a performance killer.

I'd recommend using a URL like: /IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino You would use the following rewrite rule to put the codes into the parameter and remove the slug:

RewriteRule ^/?([A-Z]+-[A-Z]+(-[A-Z]+)?).* /demo.html?code=$1

That would take any URL that has two or three abbreviations at the beginning and put them into the code parameter. That should support either your code=IT-ROM or code=IT-ROM-FCO cases you mentioned in the comments.

Then when you generate URLs on your site, put the pretty version in the hrefs:

<a href="/IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino">

You'll also need to "canonicalize" your URLs. The URL /IT-ROM-FCO/foo-bar will then show the same content. It is probably easiest to solve this by using a meta link rel canonical tag in the head of the page with the pretty URL. That will tell Google which version is your preferred URL.

<link rel="canonical" href="https://example.com/IT-ROM-FCO/airports/italy/rome/aeroporto-di-roma-fiumicino">