如何根据每年的特定日期重定向到子目录

时间:2019-07-18 16:03:06

标签: .htaccess redirect

我想使用.htaccess重定向每年在某个日期切换子目录–因此,在4月1日,重定向点指向子目录“ summer”,在9月1日,ist应该指向“ winter”子目录”。我该如何实现?

我已经建立了指向.summer子目录的基本.htaccess脚本:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?my-url.uk$
RewriteCond %{REQUEST_URI} !^/summer/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /summer/$1
RewriteCond %{HTTP_HOST} ^(www.)?my-url.uk$
RewriteRule ^(/)?$ summer/index.php [L]

1 个答案:

答案 0 :(得分:0)

在.htaccess文件顶部检查此规则。使用TIME_MON变量并检查当前月份。

RewriteEngine on

RewriteCond %{TIME_MON} =(04|05|06|07|08)
RewriteCond %{HTTP_HOST} ^(www.)?my-url.uk$
RewriteCond %{REQUEST_URI} !^/summer/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /summer/$1

RewriteCond %{TIME_MON} =(04|05|06|07|08)
RewriteCond %{HTTP_HOST} ^(www.)?my-url.uk$
RewriteRule ^(/)?$ summer/index.php [L]

RewriteCond %{TIME_MON} =(01|02|03|09|10|11|12)
RewriteCond %{HTTP_HOST} ^(www.)?my-url.uk$
RewriteCond %{REQUEST_URI} !^/winter/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /winter/$1

RewriteCond %{TIME_MON} =(01|02|03|09|10|11|12)
RewriteCond %{HTTP_HOST} ^(www.)?my-url.uk$
RewriteRule ^(/)?$ winter/index.php [L]