harry
harry

Reputation: 33

How to rewrite URL and add slug 'blog' in htaccess?

How to add in WordPress a slug (blog) only if the entry has a link date

https://example.com/2016-02-05-nowe-zycie-po-przeszczepie/

to

https://example.com/blog/2016-02-05-nowe-zycie-po-przeszczepie/
<IfModule mod_rewrite.c>
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]
</IfModule>

Upvotes: 1

Views: 318

Answers (1)

MrWhite
MrWhite

Reputation: 45829

Try something like the following at the top of your .htaccess file, before the existing WordPress directives:

# Prefix "/blog" to URL if date at start of URL-path
RewriteRule ^\d{4}-\d\d-\d\d- /blog%{REQUEST_URI} [R=302,L]

Note that this is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect - if that is the intention - once you have confirmed this works as intended. 301s are cached persistently by the browser so can make testing problematic.

Upvotes: 2

Related Questions