Forum Moderators: phranque
# Externally redirect direct client requests for /itemout\.php?id=100 as a URL-path
# to the correct URL http://example.com/media/100/test.html
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /itemout\.php\?id=([0-9]+)\ HTTP/
RewriteRule ^itemout\.php$ http://example.com/media/%1/test.html? [R=301,L]
#
# Internally rewrite requests for URL-path /media/100/test.html to
# internal server filepath plus query-string /itemout.php?id=100
RewriteRule ^media/([0-9]+)/test\.html$ /itemout.php?id=$1 [L]
# Generate a 404-Not Found response for direct client requests for /itemout\.php as a URL-path
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /itemout\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^itemout\.php$ /filepath-that-is-known-not-to-exist.xyz [L]
# Alternate RewriteRule for use only on Apache 2.2 and later
# RewriteRule ^itemout\.php$ - [R=404,L]
#
# Internally rewrite requests for URL-path /media/100/test.html to
# internal server filepath plus query-string /itemout.php?id=100
RewriteRule ^media/([0-9]+)/test\.html$ /itemout.php?id=$1 [L]
RewriteCond %{QUERY_STRING} . [edited by: jdMorgan at 10:36 pm (utc) on Dec 20, 2010]
[edit reason] Single typo correction [/edit]