skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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]
    

  2. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search