Nikolai Engel Nikolai Engel - 5 months ago 26
PHP Question

Add current year in redirect htaccess

I try to write a Rewrite Rule which route from:

/abteilungen/einsatzabteilung/einsaetze.php


to

domain.de/abteilungen/einsatzabteilung/einsaetze/2016 (CURRENT_YEAR)


My .htaccess looks now like this:

RewriteEngine on
Redirect 301 /abteilungen/einsatzabteilung/einsaetze.php %{HTTP_HOST}/abteilungen/einsatzabteilung/einsaetze/


Is it possible that the year at the end of the target get the current year and how can i do this?

Answer

in apache exist variable TIME_YEAR

RewriteEngine on
Redirect 301 /abteilungen/einsatzabteilung/einsaetze.php %{HTTP_HOST}/abteilungen/einsatzabteilung/einsaetze/%{TIME_YEAR}

try use RewriteRule

RewriteEngine On
RewriteRule ^/abteilungen/einsatzabteilung/einsaetze.php$ %{HTTP_HOST}/abteilungen/einsatzabteilung/einsaetze/%{TIME_YEAR} [R=301,L]