Search code examples
wordpressapache.htaccesshttp-redirectmod-rewrite

WordPress: Redirect Removing date from url using .htaccess


I have a redirect problem with WordPress and removing the date from the URL:

OLD:
https://www.example.de/2022/03/03/here-is-the-article-name-2582/

NEW:
https://www.example.de/here-is-the-article-name-2582/

Redirect ERROR:
https://www.example.de/03/

he redirect all the time on the "day" path.

here my .htaccess test:

########### REDIRECT 301 ############
RewriteEngine on
RewriteBase /

RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$3 [R=301,NC,L]
RewriteRule ^category(/.*|)$ /kategorie/$1 [R=301,L,NC]
RewriteRule ^tag(/.*|)$ /schlagwort/$1 [R=301,L,NC]

#RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$4

########### ALTE URL mit DATUM - REDIRECT 301 - OHNE Datum ############
#<IfModule mod_rewrite.c>
#   RewriteEngine On
#   RewriteBase /
#   RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$3 [R=301,NC,L]
#</IfModule>

What can I do for the correct routing?


Solution

  • this redirect 301 works now for me:

    ########### REDIRECT 301 ############
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$4 [R=301,NC,L]
    RewriteRule ^category(/.*|)$ /kategorie/$1 [R=301,L,NC]
    RewriteRule ^tag(/.*|)$ /schlagwort/$1 [R=301,L,NC]