WordPress Permalinks

A permalink is the permanent URL of a post or page. WordPress can show it in many styles. A good permalink is short, readable and has the main keyword of the page.

Common permalink structures

SettingExample URL
Plainhttps://example.com/?p=123
Day and namehttps://example.com/2026/02/10/sample-post/
Month and namehttps://example.com/2026/02/sample-post/
Numerichttps://example.com/archives/123
Post namehttps://example.com/sample-post/
CustomAny mix of tags, like /%category%/%postname%/

For most sites, Post name is the best choice. The structure is set in Settings > Permalinks.

See the permalink change

Terminal output

$ wp option get permalink_structure
/%postname%/
$ wp post create –post_title="Permalink demo" –post_status=publish –post_date="2026-02-10 09:00:00" –porcelain
5
$ wp eval 'echo get_permalink(5);'
http://example.com/permalink-demo/
$ wp rewrite structure '/%year%/%monthnum%/%postname%/'
Success: Rewrite structure set.
Success: Rewrite rules flushed.
$ wp eval 'echo get_permalink(5);'
http://example.com/2026/02/permalink-demo/
$ wp rewrite structure ''
Success: Rewrite structure set.
Warning: Rewrite rules are empty, possibly because of a missing permalink_structure option. Use 'wp rewrite list' to verify, or 'wp rewrite structure' to update permalink_structure.
$ wp eval 'echo get_permalink(5);'
http://example.com/?p=5
$ wp rewrite structure '/%postname%/'
Success: Rewrite structure set.
Success: Rewrite rules flushed.
$ wp eval 'echo get_permalink(5);'
http://example.com/permalink-demo/

Custom structure tags

  • %year%, %monthnum%, %day%: the date of the post.
  • %postname%: the slug of the post.
  • %category%: the category slug (the first one, if many).
  • %author%: the author name.
  • %post_id%: the post ID.

The .htaccess file

On Apache, WordPress writes the rewrite rules in the .htaccess file of the site, so that every pretty URL goes to index.php. This is the standard block:

Terminal output

$ cat .htaccess
# BEGIN WordPress

RewriteEngine On
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

On Nginx there is no .htaccess. The server configuration needs the line try_files $uri $uri/ /index.php?$args; for the same result.

Changing permalinks on a live site

If you change the structure on an old site, the old URLs are redirected by WordPress to the new ones in most cases. But your search engine rankings may still move for a while, so avoid changing it without a reason. Choose the structure before you publish content.

Note: If your posts show a 404 error after you move the site, go to Settings > Permalinks and click Save Changes. This refreshes the rewrite rules. Next: WordPress Themes.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.