I want to achieve something like this: http://example.com/year/month/day instead of http://example.com?year=yyyy&month=mm&day=dd
I want it to rewrite only when the matches are numb开发者_C百科ers only, when the first segment (year) is a 4 digit no, the 2nd segment month is between 01 and 12 (months of d year), the last segment (day) is between 01 - 31 (days in a month).
Please how can i achieve this
I think you should check month and day number in your script. But here is regexp.
Updated to match single digit day or month with optional trailing slash.
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/(0?[1-9]|[12][0-9]|3[01])/?$ ?y=$1&m=$2&d=$3
For year and month only with optional trailing slash.
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/?$ ?y=$1&m=$2
the best I can think of is this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d{4})/(0[1-9]|10|11|12)/(0[1-9]|[12][0-9]|3[01])/?$ index.php?y=$1&m=$2&d=$3 [L]
精彩评论