Forum Moderators: phranque
Now, I want to make the URL much simpler: .../p/somedir/thispage.html. In other words, I want my users to know that if they simply insert a "/p" before any URI, it will give them the printable version. I do not want it redirected; the address bar must remain "/p/...".
I've already got a bunch of rewrites working just fine, so I know the module's working. I think I'm just missing something on this one. I've tried this:
RewriteCond %{REQUEST_URI} ^/p/.*$
RewriteRule ^.*$ http://%{SERVER_NAME}/cgi-bin/print.pl?p=%{REQUEST_URI} [L]
RewriteRule ^p(/.+)$ /cgi-bin/print.pl?p=$1 [L]
(NOTE: I've removed the first part of each line and substituted "MYHOSTNAME" where appropriate so as not to identify my web site or IP address. I've also changed a couple directory names accordingly to protect the innocent.)
(4) RewriteCond: input='/p/fye/schedule.html' pattern='^/p/.*$' => matched
(2) rewrite /p/fye/schedule.html -> http://MYHOSTNAME/cgi-bin/print.pl?p=/p/fye/schedule.html
(3) split uri=http://MYHOSTNAME/cgi-bin/print.pl?p=/p/fye/schedule.html -> uri=http://MYHOSTNAME/cgi-bin/print.pl, args=p=/p/fye/schedule.html
(3) reduce http://MYHOSTNAME/cgi-bin/print.pl -> /cgi-bin/print.pl
(2) local path result: /cgi-bin/print.pl
(2) prefixed with document_root to /usr9/website/htdocs/cgi-bin/print.pl
(1) go-ahead with /usr9/website/htdocs/cgi-bin/print.pl [OK]
(2) init rewrite engine with requested uri /cgi-bin/error.pl
But something else is happening and I'm not sure what/why. Some how it got rewritten to my "error.pl" script which is my ErrorDocument for 401, 403 and 404.
My error_log says this:
File does not exist: /usr9/website/htdocs/cgi-bin/print.pl
[edited by: jdMorgan at 9:38 pm (utc) on June 26, 2006]
[edit reason] Repaired formatting [/edit]
RewriteRule ^p(/.+)$ /cgi-bin/print.pl?p=$1 [L]
That should work. Your original code invokes an external redirect, which would 'expose' the direct path to your cgi script -- not generally desirable.
File does not exist: /usr9/website/htdocs/cgi-bin/print.plSo it seems that it's now looking for an actual file; and the path is actually the real path to my script. What am I missing here?
This problem is probably not a 'how' problem -- your code looks right. This is more likely a 'where' problem, in that files are not where the mod_rewrite code thinks they are.
Jim
RewriteRule ^/p(/.+)$ /cgi-bin/print.pl?p=$1 [L]
I'm expecting it to run http://www.example.com/cgi-bin/print.pl?p=/fye/schedule.html
I'm still getting a 404 error, but I see now what it's doing. Here's my rewrite_log (with paths changed to protect the innocent):
(2) init rewrite engine with requested uri /p/fye/schedule.html
(3) applying pattern '^/p(/.+)$' to uri '/p/fye/schedule.html'
(2) rewrite /p/fye/schedule.html -> /cgi-bin/print.pl?p=/fye/schedule.html
(3) split uri=/cgi-bin/print.pl?p=/fye/schedule.html -> uri=/cgi-bin/print.pl, args=p=/fye/schedule.html
(2) local path result: /cgi-bin/print.pl
(2) prefixed with document_root to /usr9/website/htdocs/cgi-bin/print.pl
(1) go-ahead with /usr9/website/htdocs/cgi-bin/print.pl [OK]
I'm getting close eh?
With mod_rewrite doing an internal rewrite, you're basically stuck with DocumentRoot, so using a SymLink may be the best solution.
Jim
It seems that I'm just trying to make mod_rewrite do something it can't; and it's not necessarily a limitation so much as it is the way my server is setup and my filesystem is laid out.
I'll mess around with it some more. Maybe I'll just actually create a '/p/' directory at the top level of my DOCUMENT_ROOT and be done with it. :) Hmmm.
And that's why your alias worked with the redirect syntax -- The redirect response causes the client to start a new HTTP request using the new URL, and that new request enters your server 'at the top' and invokes the ScriptAlias, whereas this won't happen with an internal rewrite. Unfortunately, a redirect exposes your script by changing the URL in the browser address bar, which is undesireable.
Please post if you find a good solution!
Jim