Forum Moderators: phranque
I'm using a popular CMS that rewrites GET parameters in the URL the usual way; e.g. it turns
http://example.com/index.php?q=foo/bar
...into
http://example.com/foo/bar
So far so good. But now, I need to try to append the current year and month on to the url, and this is where the headaches start.
Judging from the available variables in Apache (listed under RewriteCond [httpd.apache.org], but also available to RewriteRule [httpd.apache.org]), this should be possible by appending %{TIME_YEAR}/%{TIME_MON} to the rewritten url.
The base RewriteRule/Cond set used by the CMS looks like this:
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Reading the Apache docs tells me that this means:
My best guess was that I should insert a new RewriteCond after 1 and rewrite the incoming url before 2. I thought this could be accomplished by adding
I thought that this should work and that step 2 could just take care of things normally, but in fact the new condition and rule have no effect whatsoever.
Can anyone point out any obvious errors with my approach or suggest an alternative?
-b
I think you need to work backwards:
Thanks, but I think I must have explained it backwards ;-)
I (somewhat bizarrely) need the requested url 'http://example.com/foo/bar' to end up at 'http://example.com/foo/bar/2007/1' (via http://www.example.com/index.php?q=foo/bar/2007/1).
Your example, as far as I can tell sends the latter to the former, but everything already works in this direction.
-b
The "real URL" is determined by what your script outputs on your pages, while the "real filepath" is determined by how you rewrite those URLs, when requested from your server, to the form needed to re-invoke your page-generation script to produce the next page.
The entire process, from a click on a link on your page, through the URL rewriting, to the generation of the next page, is explained here [webmasterworld.com].
Jim
[edited by: jdMorgan at 10:27 pm (utc) on Jan. 17, 2007]