Home > Mobile >  WordPress: Redirect Removing date from url using .htaccess
WordPress: Redirect Removing date from url using .htaccess

Time:03-06

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?

CodePudding user response:

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]

CodePudding user response:

I see that you found the problem and changed your rule to use the fourth capturing group rather than the third.

There is another solution. You can remove unused capturing groups from your rule by removing unneeded parenthesis. Then you can us the first (and only) capturing group.

RewriteRule ^[0-9] /[0-9] /[0-9] /(.*)$ /$1 [R=301,NC,L]
  • Related