rewrite utf8 characters in htaccess - apache

I am trying to rewrite é to e, using the htaccess file.
All the following rules have all failed.
RewriteRule ^(.*)é(.*) $1e$2 [R,L]
RewriteRule ^(.*)\xc3\xa9(.*) $1e$2 [R,L]
RewriteRule ^(.*)%C3%A9(.*) $1e$2 [R,L]
I have the following debug output, however am unable to figure out what it says.
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (2) init rewrite engine with requested uri /translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) applying pattern '^(.*)' to uri '/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/'
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) applying pattern '^(.*)' to uri '/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/'
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (1) pass through /translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/speaksheets.com/public_html/] add path info postfix: /home/speaksheets.com/public_html/translation -> /home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/speaksheets.com/public_html/] strip per-dir prefix: /home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/ -> translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/speaksheets.com/public_html/] applying pattern '^index\.php$' to uri 'translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/'
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/speaksheets.com/public_html/] add path info postfix: /home/speaksheets.com/public_html/translation -> /home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/speaksheets.com/public_html/] strip per-dir prefix: /home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/ -> translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/speaksheets.com/public_html/] applying pattern '.' to uri 'translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/'
197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (2) [perdir /home/speaksheets.com/public_html/] rewrite 'translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/' -> '/index.php'
The question is, what is wrong with this rule, RewriteRule ^(.*)\xc3\xa9(.*) $1e$2 [R,L]?

Your rule:
RewriteRule ^(.*)\xc3\xa9(.*) $1e$2 [R,L]
Is fine and should work (worked in my testing also).
But from rewrite log it appears some rule in internally rewriting it to index.php first.
Just make sure this above rule is very first rule in your .htaccess.

URLs cannot contain non-ASCII characters. All non-ASCII characters must be escaped to percent escapes like %C3%A9. ^(.*)é(.*) should never match a valid URL. \xYY is not defined as a byte escape sequence in Apache as far as I'm aware, so ^(.*)\xc3\xa9(.*) does not mean what you think it means either. The only valid rule is ^(.*)%C3%A9(.*), which contains the URL escaped version of a UTF-8 representation of "é".

Related

Rewrite rules not working with .htaccess but do with vhost

I am a little miffed by this one, the rules I am pretty sure are correct yet when using them in a .htaccess file they just won't apply.
The rules push everything through a dispatch.php which then handles my MVC views and controllers for me.
//htaccess file - Accessing http://topaz.local/app/users/login
RewriteEngine On
RewriteCond %{REQUEST_URI} !dispatch/.php$
RewriteCond /var/www/topaz%{REQUEST_FILENAME} !-f
RewriteRule ^(/.*)$ /dispatch.php?url=$1 [L,QSA]
RewriteRule ^x/.!dispatch/.php([^b]+)!dispatch/.php$ !dispatch/.php [L,NE]
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] add path info postfix: C:/var/www/topaz/app/users -> C:/var/www/topaz/app/users/login
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] strip per-dir prefix: C:/var/www/topaz/app/users/login -> app/users/login
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] applying pattern '^(/.*)$' to uri 'app/users/login'
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] add path info postfix: C:/var/www/topaz/app/users -> C:/var/www/topaz/app/users/login
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] strip per-dir prefix: C:/var/www/topaz/app/users/login -> app/users/login
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] applying pattern '^x/.!dispatch/.php([^b]+)!dispatch/.php$' to uri 'app/users/login'
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] pass through C:/var/www/topaz/app/users
Compared to the output via the vhost:
[topaz.local/sid#18374e8][rid#1868310/initial] init rewrite engine with requested uri /app/users/login
[topaz.local/sid#18374e8][rid#1868310/initial] applying pattern '^(/.*)$' to uri '/app/users/login'
[topaz.local/sid#18374e8][rid#1868310/initial] rewrite '/app/users/login' -> '/dispatch.php?url=/app/users/login'
[topaz.local/sid#18374e8][rid#1868310/initial] split uri=/dispatch.php?url=/app/users/login -> uri=/dispatch.php, args=url=/app/users/login
[topaz.local/sid#18374e8][rid#1868310/initial] local path result: /dispatch.php
[topaz.local/sid#18374e8][rid#1868310/initial] prefixed with document_root to C:/var/www/topaz/dispatch.php
[topaz.local/sid#18374e8][rid#1868310/initial] go-ahead with C:/var/www/topaz/dispatch.php [OK]

mod_rewrite mysterious subreq

Seems like some apache module is interfering with my request uris as it suffixes ".html" to it.
My rewrite log:
172.16.103.1 - - [08/Mar/2012:14:56:33 +0100] [www.example.org/sid#7ff723575b58][rid#7ff724b4fc58/initial] (1) pass through /folder/subfolder/
172.16.103.1 - - [08/Mar/2012:14:56:33 +0100] [www.example.org/sid#7ff723575b58][rid#7ff724b42468/subreq] (3) [perdir /srv/www/html/project/] add path info postfix: /srv/www/html/project/folder/subfolder.html -> /srv/www/html/trustedshops/folder/subfolder.html/
172.16.103.1 - - [08/Mar/2012:14:56:33 +0100] [www.example.org/sid#7ff723575b58][rid#7ff724b42468/subreq] (3) [perdir /srv/www/html/project/] strip per-dir prefix: /srv/www/html/project/folder/subfolder.html/ -> folder/subfolder.html/
This merely happens on our development servers. But It's hard do compare the whole apache config. Any ideas which module could be responsible?
Turn off MultiViews as this generates subrequests
Ditto DirectoryIndex with a list of possiblities.
Use the NS flag on your rewrite rules, or
RewriteCond %{IS_SUBREQ} t
RwriteRule ^ - [L]

Why doesn't the RewriteCond prevent the RewriteRule from processing?

I've got the following in my .conf file used for cache busting js:
<Directory "/www/virtual/site/html/js/">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\d+\/(.+)$ $1 [L]
</Directory>
The idea here is to rewrite site.com/js/123456/script.js to site.com/js/script.js
(The rewriting works just fine)
If I look at the rewrite log the part I'm not understanding is that it is applying the RewriteRule to the script after the interal redirect... Shouldn't the %{REQUEST_FILENAME} !-f prevent it from processing the RewriteRule since the file exists?
Rewrite Log
[rid#2b607f8f2dc8/initial] (3) [perdir /www/virtual/site2/html/js/] add path info postfix: /www/virtual/site2/html/js/1234 -> /www/virtual/site2/html/js/1234/script.js
[rid#2b607f8f2dc8/initial] (3) [perdir /www/virtual/site2/html/js/] strip per-dir prefix: /www/virtual/site2/html/js/1234/script.js -> 1234/script.js
[rid#2b607f8f2dc8/initial] (3) [perdir /www/virtual/site2/html/js/] applying pattern '^\d+\/(.+)$' to uri '1234/script.js'
[rid#2b607f8f2dc8/initial] (2) [perdir /www/virtual/site2/html/js/] rewrite '1234/script.js' -> 'script.js'
[rid#2b607f8f2dc8/initial] (3) [perdir /www/virtual/site2/html/js/] add per-dir prefix: script.js -> /www/virtual/site2/html/js/script.js
[rid#2b607f8f2dc8/initial] (2) [perdir /www/virtual/site2/html/js/] strip document_root prefix: /www/virtual/site2/html/js/script.js -> /js/script.js
[rid#2b607f8f2dc8/initial] (1) [perdir /www/virtual/site2/html/js/] internal redirect with /js/script.js [INTERNAL REDIRECT]
[rid#2b6073eb14a8/initial/redir#1] (3) [perdir /www/virtual/site2/html/js/] strip per-dir prefix: /www/virtual/site2/html/js/script.js -> script.js
[rid#2b6073eb14a8/initial/redir#1] (3) [perdir /www/virtual/site2/html/js/] applying pattern '^\d+\/(.+)$' to uri 'script.js'
[rid#2b6073eb14a8/initial/redir#1] (1) [perdir /www/virtual/site2/html/js/] pass through /www/virtual/site2/html/js/script.js
mod_rewrite (by design) keeps on applying rewrite-rules, till the url no longer changes.
So the first time it rewrite 1234/script.js to script.js the second time it tries to apply the rule, the pattern regular expression doesn't match and script.js is 'passed through'.
This is the way it is supposed to work. It can sometimes be a pain, but it makes mod_rewrite a lot more powerful/useful.
edit
mod_rewite first tests the RewriteRule pattern, before trying to apply the RewriteCond's. This is so you can use backreferences $0, $1 etc. in your RewriteCond. After all the RewriteCond's it will create the substitution string, so it can also use backrefereces %0, %1. etc. See also the diagram below.
So this is why it tried to apply the pattern before testing if the file exists.

Apache Mod Rewrite does not rewrite file name

i have the following problem:
On the download dialog on each browser it displays me only the dot extension filename
like .divx
But i want the full name eg
http://example.com/14558/.divx rewrites to 14558.divx and not onyly .divx
I want see on every browser dialog the number and the extension.
like 14558.divx
How i can solve this problem ??
RewriteRule ^([0-9]+)/.divx$ $1.divx
RewriteRule ^([0-9]+)/.mkv$ $1.mkv
RewriteRule ^([0-9]+)/.avi$ $1.avi
Current Configuration:
RewriteRule ^([0-9]+)/\.(divx|mkv|avi)$ /$1.$2
Rewrite Log:
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (3) [perdir F:/media/video_files/] add path info postfix: F:/media/video_files/29 -> F:/media/video_files/29/.mkv
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (3) [perdir F:/media/video_files/] strip per-dir prefix: F:/media/video_files/29/.mkv -> 29/.mkv
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (3) [perdir F:/media/video_files/] applying pattern '^([0-9]+)/\.(divx|mkv|avi)$' to uri '29/.mkv'
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (2) [perdir F:/media/video_files/] rewrite '29/.mkv' -> '/29.mkv'
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (1) [perdir F:/media/video_files/] internal redirect with /29.mkv [INTERNAL REDIRECT]
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae588f8/initial/redir#1] (3) [perdir F:/media/video_files/] strip per-dir prefix: F:/media/video_files/29.mkv -> 29.mkv
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae588f8/initial/redir#1] (3) [perdir F:/media/video_files/] applying pattern '^([0-9]+)/\.(divx|mkv|avi)$' to uri '29.mkv'
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae588f8/initial/redir#1] (1) [perdir F:/media/video_files/] pass through F:/media/video_files/29.mkv
Your rewriterules seem ok... err well maybe it's the backslash. By the way you could optimize in a nicer way (not tested):
RewriteRule ^([0-9]+)/\.(divx|mkv|avi)$ /$1.$2
But the only way to solve your problem (= show the whole filename) is to make a full redirect to a URL that has the full filename.
So in your case redirect would mean these rules:
RewriteRule ^([0-9]+)/\.(divx|mkv|avi)$ $1.$2 [QSA,R=301,L]
And that implies that the URLs like "14558.divx" and "1526.mkv" have to be valid and return the file.
Two hints:
Please try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

More Eyeballs on my Poor mod_rewrite Attempt Please

We're changing the way users embed images in their blogs, but I need to make sure previously embedded images are still displayed.
I'm trying to redirect legacy image embed links to either a static image or a single legacy image embed handling file. I'm using mod_rewrite, but it appears I fail. Amazingly, I've managed to cobble together a functional ruleset that prevents hotlinking.
I'm having some difficulty with redirecting legacy embeds to the single legacy handler though. This rule comes under the hotlink set [L], so should only be evaluated if the embed request isn't a result of hotlinking.
Here is my attempt at redirecting all requests to any file like gp[2]?.php[5]?\?p=(.*)
RewriteRule %{REQUEST_FILENAME} gp[2]?\.php[5]?(.*)=(.*)$ [NC]
RewriteRule gp[2]?\.php[5]?(.*)=(.*)$ /legacy/gp.php5$1=$2 [L]
But it doesn't work, I just get my wonderful 404 page.
Some example requests:
http://ecpod.com/includes/gp.php5?p=cfcfbfbe5d9d63eab4a3e784bd30cfe016fcfcfbfbe5d9d6a19ebc57139d56bb
http://www.ecpod.com/includes/gp.php5?p=928e3888a526b462b684aea5609016f928e3888a585d0963ac4ebb335a522e09
http://www.ecpod.com/includes/gp2.php?p=cfcfbfbe5d9d63eab4a3e784bd30cfe016fcfcfbfbe5d9d6a19ebc57139d56bb
What I'm aiming for is to have any request that looks like one of those examples directed to:
http://ecpod.com/legacy/gp.php?p=HASH
Thank you for any help.
Edit:
Legacy urls will have gp|gp2, php|php5 and a query string of n length. They may not necessarily be in the includes directory. It's messy and horrible, I know. Image embeds are handled differently now, this shall never happen again.
Logs:
RewriteRule ^/(includes/)?gp2?\.php5?$ /legacy/gp.php5 [NC,L]
192.168.1.4 - - [06/Sep/2010:14:44:27 +1200] [www.ecpod-dev.dev/sid#2b7d543aa390][rid#2b7d68ec65a8/initial] (3) [perdir /site/http/web/] add path info postfix: /site/http/web/includes -> /site/http/web/includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:44:27 +1200] [www.ecpod-dev.dev/sid#2b7d543aa390][rid#2b7d68ec65a8/initial] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/includes/gp.php -> includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:44:27 +1200] [www.ecpod-dev.dev/sid#2b7d543aa390][rid#2b7d68ec65a8/initial] (3) [perdir /site/http/web/] applying pattern '^/(includes/)?gp2?\.php5?$' to uri 'includes/gp.php'
192.168.1.4 - - [06/Sep/2010:14:44:27 +1200] [www.ecpod-dev.dev/sid#2b7d543aa390][rid#2b7d68ec65a8/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes
RewriteCond %{QUERY_STRING} (^|&)(p=[^&]+)(&|$) [NC]
RewriteRule ^/(includes/)?gp2?\.php5?$ /legacy/gp.php5?%2 [NC,L]
192.168.1.4 - - [06/Sep/2010:14:43:53 +1200] [www.ecpod-dev.dev/sid#2b8a2ad73400][rid#2b8a2b0ed438/initial] (3) [perdir /site/http/web/] add path info postfix: /site/http/web/includes -> /site/http/web/includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:43:53 +1200] [www.ecpod-dev.dev/sid#2b8a2ad73400][rid#2b8a2b0ed438/initial] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/includes/gp.php -> includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:43:53 +1200] [www.ecpod-dev.dev/sid#2b8a2ad73400][rid#2b8a2b0ed438/initial] (3) [perdir /site/http/web/] applying pattern '^/(includes/)?gp2?\.php5?$' to uri 'includes/gp.php'
192.168.1.4 - - [06/Sep/2010:14:43:53 +1200] [www.ecpod-dev.dev/sid#2b8a2ad73400][rid#2b8a2b0ed438/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes
RewriteRule /gp2?\.php5?$ /legacy/gp.php5 [NC,L]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (3) [perdir /site/http/web/] add path info postfix: /site/http/web/includes -> /site/http/web/includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/includes/gp.php -> includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'includes/gp.php'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (2) [perdir /site/http/web/] rewrite 'includes/gp.php' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642756c0/initial/redir#1] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642756c0/initial/redir#1] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642756c0/initial/redir#1] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642756c0/initial/redir#1] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b1264277fa8/initial/redir#2] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b1264277fa8/initial/redir#2] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b1264277fa8/initial/redir#2] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b1264277fa8/initial/redir#2] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427a7e8/initial/redir#3] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427a7e8/initial/redir#3] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427a7e8/initial/redir#3] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427a7e8/initial/redir#3] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427cfe0/initial/redir#4] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427cfe0/initial/redir#4] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427cfe0/initial/redir#4] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427cfe0/initial/redir#4] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427f948/initial/redir#5] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427f948/initial/redir#5] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427f948/initial/redir#5] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427f948/initial/redir#5] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c3048/initial/redir#6] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c3048/initial/redir#6] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c3048/initial/redir#6] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c3048/initial/redir#6] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c5800/initial/redir#7] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c5800/initial/redir#7] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c5800/initial/redir#7] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c5800/initial/redir#7] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c81f0/initial/redir#8] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c81f0/initial/redir#8] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c81f0/initial/redir#8] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c81f0/initial/redir#8] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cad80/initial/redir#9] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cad80/initial/redir#9] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cad80/initial/redir#9] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cad80/initial/redir#9] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cd840/initial/redir#10] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cd840/initial/redir#10] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cd840/initial/redir#10] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cd840/initial/redir#10] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
Outside <Directory>:
http://www.ecpod-dev.dev/includes/gp.php?p=ff2287e8bb45572e38304afa184ba1a464016fff2287e8bb45572e0606111e7a
RewriteRule ^/(includes/)?gp2?\.php5?$ /legacy/gp.php5 [NC,L]
192.168.1.4 - - [06/Sep/2010:23:46:54 +1200] [www.ecpod-dev.dev/sid#2ac33a5a83d0][rid#2ac34f0c4608/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes
RewriteCond %{QUERY_STRING} (^|&)(p=[^&]+)(&|$) [NC]
RewriteRule ^/(includes/)?gp2?\.php5?$ /legacy/gp.php5?%2 [NC,L]
192.168.1.4 - - [06/Sep/2010:23:47:47 +1200] [www.ecpod-dev.dev/sid#2b02af320470][rid#2b02bcb7b688/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes
RewriteRule /gp2?\.php5?$ /legacy/gp.php5 [NC,L]
192.168.1.4 - - [06/Sep/2010:23:48:45 +1200] [www.ecpod-dev.dev/sid#2aea076a73b0][rid#2aea14f025a8/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes
The input to the RewriteRule test pattern will not contain the query string, so testing for it will prevent the rule from ever matching and applying.
Taking that into account, we can rework the rule into something like this:
RewriteRule ^(includes/)?gp2?\.php5?$ /legacy/gp.php5 [NC,L]
Assuming that the query string will already be in the format you want, we can just let mod_rewrite append it automatically by not specifying a replacement in our rewrite.
If you aren't sure that the query string will always be just p=HASH, and want to guarantee that it will be for the target script, we can extend the rule block to take that into account, looking for the p parameter in the query string and replacing the existing query string with just that piece:
RewriteCond %{QUERY_STRING} (^|&)(p=[^&]+)(&|$) [NC]
RewriteRule ^(includes/)?gp2?\.php5?$ /legacy/gp.php5?%2 [NC,L]
Per Roland Illig's comment, you could also do the following to be less restrictive on the directory the file is in:
RewriteCond %{REQUEST_URI} !^/legacy/
# Input to RewriteRule in .htaccess never has a leading slash, so make sure
# we're at the beginning or there was a slash before the filename
RewriteRule (^|/)gp2?\.php5?$ /legacy/gp.php5 [NC,L]
Edit: Changed rules to reflect how they would be defined in httpd.conf instead of .htaccess.
Edit: ...And then changed it back again.
This should do it:
RewriteRule ^\/includes\/gp\.php5?\?p=([a-f,0-9]{64})$ /legacy/gp.php?p=$1