Reputation: 57
i have a wordpress site and want to add a timestamp in url like this:
date,hour,minutes at end of my url (?201503291854) example:
example.com/pagename?201503291854
example.com/page/2/?201503291854
but if user visit the url with 1854 at end and if time now is 19:00 link will be
example.com/pagename?201503291900
Upvotes: 1
Views: 3087
Reputation: 360
I had to find a way to do that in order to avoid the caching system of Facebook and Twitter (for their og:tags), while reaching a dynamically generate picture (so their cache system didn't trigger the change).
Here is how I done that.
You will, of course, need Apache mod_rewrite.
Here is what I put in my .htaccess :
RewriteRule ^(.*)$ http://stuff.com/profile.php?customURL=$1&ts=%{TIME_YEAR}%{TIME_MON}%{TIME_DAY}_%{TIME_HOUR} [NC,L]
And here is what you can insert :
Year:
%{TIME_YEAR}
Month :
%{TIME_MON}
Day :
%{TIME_DAY}
Hour :
%{TIME_HOUR}
Min :
%{TIME_MIN}
Sec :
%{TIME_SEC}
When tested on the twitter validator, I then successfully got :
profile.php?customURL=testing&ts=20160913_16
or (with min and sec)
profile.php?customURL=testing&ts=20160913_164108
Here you can find good cheatsheet for modrewrite : http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html
In case the above link goes down, here it's on webarchive (at today date) : http://web.archive.org/web/20160821181903/http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html
Upvotes: 2