SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    North Wales, UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question mod_rewrite question - matching the date?

    How, using mod_rewrite, would I map any requests that contain today's date to a specific URL? I know that there are Apache constants representing the year/month/day etc. but I haven't been successful in matching them in the request.

    So given that today's the 13th Feb, I want to map any requests to www.domain.com/13-02-2005/ to another page.

    Here's what I have:

    RewriteBase /
    RewriteRule ^%{TIME_DAY}-%{TIME_MONTH}-%{TIME_YEAR}/(.*) otherscript.php$1

    But this doesn't seem to work - any help would be greatly appreciated!

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    tf,

    For others, tf has found the exact Apache variables that he/she needs:
    Quote Originally Posted by http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteCond
    Server-Variables: These are variables of the form

    %{ NAME_OF_VARIABLE }

    where NAME_OF_VARIABLE can be a string taken from the following list:
    HTTP headers:

    HTTP_USER_AGENT
    HTTP_REFERER
    HTTP_COOKIE
    HTTP_FORWARDED
    HTTP_HOST
    HTTP_PROXY_CONNECTION
    HTTP_ACCEPT

    connection & request:

    REMOTE_ADDR
    REMOTE_HOST
    REMOTE_USER
    REMOTE_IDENT
    REQUEST_METHOD
    SCRIPT_FILENAME
    PATH_INFO
    QUERY_STRING
    AUTH_TYPE

    server internals:

    DOCUMENT_ROOT
    SERVER_ADMIN
    SERVER_NAME
    SERVER_ADDR
    SERVER_PORT
    SERVER_PROTOCOL
    SERVER_SOFTWARE

    system stuff:

    TIME_YEAR
    TIME_MON
    TIME_DAY
    TIME_HOUR
    TIME_MIN
    TIME_SEC
    TIME_WDAY
    TIME

    specials:

    API_VERSION
    THE_REQUEST
    REQUEST_URI
    REQUEST_FILENAME
    IS_SUBREQ
    Unfortunately, tf didn't note that these environmental variables MUST be used in RewriteCond(ition) statements (RewriteRules ONLY deal with the %{REQUEST_URI} string), i.e.,
    Code:
    RewriteCond %{TIME_DAY} ^([0-9]{1,2})$
    RewriteCond %{TIME_MONTH} ^([0-9]{1,2})$
    RewriteCond %{TIME_YEAR} ^([0-9]{4})$
    RewriteRule ^/?$1-%2-%3/(.*)$ otherscript.php?$1
    Note: Don't forget to add the ? for the query string!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •