What Are WordPress Permalinks?

This is a question I’m asked quite a lot by my clients at WP Service Masters. Maybe I should answer this there, and I will do at some point, but until I do, here’s an explanation of what a permalink is and why we use them.

Just like desktop and laptop computers, web servers store files in directories. Directory names end in forward slashes and file names don’t. For example:

/Directory/Directory/Directory/

and

Directory/Directory/File

Notice there is no slash after ‘File’ in the second example.

When you view a web page you are effectively viewing a file stored on a server or you are running a script on a server that writes a web page for you to view.

Incidentally, the difference between HTML and PHP is that HTML pages are static whereas PHP pages are scripts that dynamically build web pages whenever they are viewed.

When you use a file browser in a Windows computer, it lists the drive letter in front of the directory listing. For example

c:\Directory\File

A Linux computer treats all storage devices as individual directories on one storage device instead of individual drives so it lists the directory without a drive name. For example

/Directory/File

Notice the slash in the Linux directory listing points the opposite way to the slash in the Windows directory listing. Linux uses forward slashes, Windows uses backslashes.

Most web servers are Linux servers that run the Apache server software.

When you point your web browser to a web server you type in an address similar to http://example.com/.

The ‘http’ bit tells your computer to look for a remote Internet location and not a local storage device such as c:\example\file.

example.com/ is a directory. It is a site’s root directory i.e the place where the site is hosted on the server.

Permalinks (or Fancy URLs) make it easy for people to remember a file’s location on the web and make the page indexable by search engines.

When you write a WordPress post or page, WordPress doesn’t create a physical file for that post or page. Instead, it creates an entry in its database.

Until WordPress permalinks are set in Dashboard > Settings > Permalinks, all WordPress post and page links look similar to example.com/?p=1234 and example.com/?p=4321.

The number tells WordPress where to look in its database to retrieve a post’s content.

When a surfer arrives to view that file, WordPress checks the database for the content the surfer wants to see then serves a virtual file. That’s to say, the dynamic script called index.php that launches WordPress when someone visits a WordPress site, reads the URL request and causes WordPress to read its database, fetch the correct content then build the page to serve that content.

The bit after the question mark in the URL is called a query string. Search engines hate query strings; and query strings tell visitors and search engines little about the post that’s being viewed. Think keywords, post date and the directory structure that would exist were the post a real file.

Setting WordPress permalinks allows you to change

example.com/?p=4321

into URLs similar to

example.com/year/month/day/post-title

or

example.com/year/month/post-title

In the post editor screen you will see a permalink URL displayed below the post title. You can edit this permalink if you change the title or if you dislike the permalink created by WordPress. The part of the URL that you can edit is called the post slug.

If you do edit a post slug after publishing a post or page, make sure you have a plugin like Redirection installed. Redirection will automatically monitor post and page URL changes and create redirections from old URLs to  new URLs when changes are made.

How to Change WordPress Permalinks in an Old Blog

If you’ve used a permalink structure that no longer suits your  site or if your URL structure is hurting your SEO (search engine optimization), you  can change your permalink structure by following these steps:

  1. Install and Activated the Redirection plugin
  2. Navigate to Dashboard > Tools > Redirection
  3. Select “Options” and check the option to “monitor modified posts” under “Monitor URLs”
  4. Go to Dashboard > Settings > Permalinks
  5. Enter your new permalink structure and click save

Check your site is redirecting old URLs to their new URLs by searching Google for some of your posts.

My current URL structure is based on the notion that Google ranks keywords in URLs . It also places a post ID after the URL to help get posts listed in Google News. My permalink structure is:

/%category%/%postname%-%post_id%

When categories are used in the permalink structure, if a post is assigned multiple categories the slug for the post’s lowest category ID is used in its URL.

How Does the Server Know to Load WordPress?

Look at the basic WordPress rewrite rules:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

See the bit that says?

RewriteCond %{REQUEST_FILENAME} !-f

It tells the Apache server to check that the request is not for a real file stored on the server.

See the bit that says?

RewriteCond %{REQUEST_FILENAME} !-d

It tells the Apache server to check that the request is not for a real directory on the server.

If a URL request is for neither a real file or a real directory then the server loads the WordPress index.php script.

Sharing is caring!

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x