LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   mod_rewrite RewriteMap - possible to send 404? (https://www.linuxquestions.org/questions/linux-software-2/mod_rewrite-rewritemap-possible-to-send-404-a-719596/)

sneakyimp 04-16-2009 10:12 AM

mod_rewrite RewriteMap - possible to send 404?
 
In my strenuous efforts to get SEO-friendly urls, I'm using a rewrite map in my apache setup:

Code:

RewriteEngine on
RewriteOptions MaxRedirects=5

RewriteMap seo prg:/Applications/MAMP/htdocs/map.php

#map requests for the original file to the new SEO friendly urls
RewriteCond %{REQUEST_FILENAME} ^/education/db/ug/ug
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -f
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^/education/db/ug/(ug.*)$ ${seo:$1?%1}? [L,R=301]

My rewrite map is a PHP script which checks my database for an id value supplied in the query string and if anything is found, it returns an SEO-friendly text string which i inject into the URL in order to turn a url like this:
Code:

http://mydomain.com/r.php?id=1234
into one like this:
Code:

http://mydomain.com/amazing-and-useful-url/1234
I'm wondering a few things:
1) If an id is not found in my database, can I send a 404 signal from my map program? If so, how?
2) What's the story with RewriteLock. The documentation is rather tightlipped about the need for it. Am I to understand that if I use a PHP script (or any other program) as a rewrite map that I need a RewriteLock file? What are the required permissions on this file? Can I assume that apache needs to read/write it and will maintain anything it might contain?
3) I'm getting quite concerned about a lengthy list of RewriteCond and RewriteRule items in this particular apache conf file. Is there any way to have apache skip the remainder of rules in this conf file if one fails?
4) is PHP ill-suited to this obviously mission-critical and performance-critical mission? Should I bother writing a C or C++ program?


All times are GMT -5. The time now is 08:19 PM.