I'm not much of an Apache guru so I'm looking to the readership of Wizbang to help with a specialized modrewrite problem. I've got a directory called author of the root of all of the sites which contains two files - index.php and author.xml. Respectively they allow for author archives and author RSS feeds when passed the right variables.
What I'd like to do is show prettier URL's that the server will then translate into the proper parameterized call. If you're up for the challenge read on...
I'd like: http://wizbangblog.com/author/Kevin Aylward/ to actually load the following: http://wizbangblog.com/author/index.php?author=Kevin%20Aylward.
Also I'd like http://wizbangblog.com/author/Kevin Aylward/rss.xml to load the following: http://wizbangblog.com/author/author.xml?author=Kevin%20Aylward.
The only wrinkle is that I'd also like to use the solution on the subsites, which while they are addressed as third level domains (i.e. http://pop.wizbangblog.com/author/index.php?author=Kevin%20Aylward) are actually physically located in the directory structure under wizbangblog.com (ie. wizbangblog.com/pop/). I'm not sure that makes a difference, as each has their own .htaccess, but I wanted to give maximum detail.
Here is the current .htaccess. It's basically just the Movable Type generated stuff to do dynamic publishing.
- ## %%%%%%% Movable Type generated this part; don't remove this line! %%%%%%%
# Disable fancy indexes, so mtview.php gets a chance...
Options -Indexes +SymLinksIfOwnerMatch
# The mod_rewrite solution is the preferred way to invoke # dynamic pages, because of its flexibility.
# Add mtview.php to the list of DirectoryIndex options, listing it last,
# so it is invoked only if the common choices aren't present...
DirectoryIndex index.php index.html index.htm default.htm default.html default.asp /mtview.php
RewriteEngine on
# don't serve mtview.php if the request is for a real directory
# (allows the DirectoryIndex lookup to function)
RewriteCond %{REQUEST_FILENAME} !-d# don't serve mtview.php if the request is for a real file
# (allows the actual file to be served)
RewriteCond %{REQUEST_FILENAME} !-f
# anything else is handed to mtview.php for resolution
RewriteRule ^(.*)$ /mtview.php [L,QSA]
# if mod_rewrite is unavailable, we forward any missing page
# or unresolved directory index requests to mtview
# if mtview.php can resolve the request, it returns a 200
# result code which prevents any 4xx error code from going
# to the server's access logs. However, an error will be
# reported in the error log file. If this is your only choice,
# and you want to suppress these messages, adding a "LogLevel crit"
# directive within your VirtualHost or root configuration for
# Apache will turn them off.
ErrorDocument 404 /mtview.php
ErrorDocument 403 /mtview.php
## ******* Movable Type generated this part; don't remove this line! *******
One question is whether the code should go above the MT section or within it. I've been wholly unsuccessful at adding a proper RewriteRule to that structure and having it do anything short of generating 500 errors.
Any modrewrite gurus in the house who can get this to work? If so let fly with you're proposed solutions, and I'll test them out. The working solution will be credited to whoever comes up with in an article to submitted for publication on Six Apart's ProNet site.



Comments (8)
I'm no expert but I manage ... (Below threshold)1. Posted by King of Fools | April 11, 2006 6:28 PM | Score: 0 (0 votes cast)
I'm no expert but I manage to get by with what I know (and alot of help from the net)...this code is conceptual and completely untested, but off the top of my head, the first way I would approach the problem would be something like this:
It should work for both domain and sub-domain requests (once it is tested and made functional that is!)
1. Posted by King of Fools | April 11, 2006 6:28 PM |
Score: 0 (0 votes cast)
Posted on April 11, 2006 18:28
2. Posted by King of Fools | April 11, 2006 7:38 PM | Score: 0 (0 votes cast)
Ok, {request_uri} might not be the right variable or the Cond regexp may need some tweaking (I think request_uri may include the domain, but shouldn't include the transport {http://})
On the RequestCond lines, remove the '^' and it might work better.
2. Posted by King of Fools | April 11, 2006 7:38 PM |
Score: 0 (0 votes cast)
Posted on April 11, 2006 19:38
3. Posted by Kevin | April 11, 2006 11:43 PM | Score: 0 (0 votes cast)
I'll try it out and let you know... Thanks!
3. Posted by Kevin | April 11, 2006 11:43 PM |
Score: 0 (0 votes cast)
Posted on April 11, 2006 23:43
4. Posted by McGehee | April 11, 2006 11:44 PM | Score: 0 (0 votes cast)
Everything I know about mod_rewrite I got from the folks at pMachine. And maybe a website I found via Dogpile, but that didn't help much.
4. Posted by McGehee | April 11, 2006 11:44 PM |
Score: 0 (0 votes cast)
Posted on April 11, 2006 23:44
5. Posted by Kevin | April 12, 2006 12:56 AM | Score: 0 (0 votes cast)
No luck. I even tried this, which looks like it should work.
I'm thinking that the DirectoryIndex line that adds mtview.php to the indexes screws me up. When I do get something that works I get the mtview.php file not found page.
5. Posted by Kevin | April 12, 2006 12:56 AM |
Score: 0 (0 votes cast)
Posted on April 12, 2006 00:56
6. Posted by ed | April 12, 2006 3:52 AM | Score: 0 (0 votes cast)
Hmmm.
This is probably redundant:
www.modrewrite.com
Sorry but I don't know much about it, never really had a need so far, and I'm a little strapped for time right now.
6. Posted by ed | April 12, 2006 3:52 AM |
Score: 0 (0 votes cast)
Posted on April 12, 2006 03:52
7. Posted by Kathy K | April 12, 2006 6:54 AM | Score: 0 (0 votes cast)
RewriteRule ^/author/(.*)/? /author/index.php?author=%1 [QSA,L]
RewriteRule ^/author/(.*)/rss.xml$ /author/author.xml?author=%1 [QSA,L]
Try that - right below the "Rewrite Engine On"
(above the mtview stuff)
Try one at a time - one might work while another doesn't.
(I'm half asleep right now and I'm not used to working without a rewrite base, so no guarantees...)
7. Posted by Kathy K | April 12, 2006 6:54 AM |
Score: 0 (0 votes cast)
Posted on April 12, 2006 06:54
8. Posted by Kathy K | April 12, 2006 6:55 AM | Score: 0 (0 votes cast)
Oh... and if it DOES work, I don't want my name at Six Apart.
8. Posted by Kathy K | April 12, 2006 6:55 AM |
Score: 0 (0 votes cast)
Posted on April 12, 2006 06:55