httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Theo <t...@theoretic.com>
Subject [users@httpd] mod_rewrite to shorten URLs (problem)
Date Sun, 22 Dec 2002 19:11:41 GMT
Hello, all. I took a look through the HTTPD FAQ 
<http://httpd.apache.org/docs/misc/FAQ.html> and the Practical Solutions 
for URL-Manipulation 
<http://www.engelschall.com/pw/apache/rewriteguide/>, but did not find 
any solution that fit my problem well enough, so I'm hoping someone here 
can help. I apologize for this very long post, but I believe providing 
too much information right off is better than not enough (I hate those 
one-line "I have a problem, pleez help" posts). Most of this is debug 
from logs.

I'm trying to accomplish what I would think is a simple task: shorten a 
URL using mod_rewrite. But So far all attempts have failed. I'm about to 
pull my hair out.

I have a virtual host with its DocumentRoot at /home/theoretic/test. The 
URL for his DocumentRoot is http.test.theoretic.com. The directories and 
files in this DocumentRoot are:

    <dir> bin
    <dir> patches
    <dir> templates
    <dir> data
    <dir> lib
    <dir> packages
    <dir> pub
    <dir> tools
    <file> index.html
    <file> rewrite_log

I have installed TWiki (www.twiki.org) in this space, with its CGI 
scripts in /bin, attachments in /pub, and data files in /data. This is 
different from the standard TWiki setup because I have them directly in 
my DocumentRoot, not a subdirectory called "twiki". I have asked on the 
TWiki forums, BTW, but from the little help I've gotten there it seems 
it is not a TWiki problem, just my dumb ass mis-configuring mod_rewrite.

The URL for TWiki pages is http://test.theoretic.com/bin/view/WEB/TOPIC, 
where /bin is the cgi-bin directory of the CGI scripts, /view is 
actually a CGI script that parses and displays the TWiki data, /WEB is a 
TWiki category (it actually exists as a subdirectory of /data), and 
/TOPIC is the TWiki page (it exists as a '.txt' file in the WEB 
directory under /data).

I am wanting to shorten this URL to simply 
http://test.theoretic.com/WEB/TOPIC, removing the /bin/view part.

One consideration is that URLs that explicitly use the /bin or /pub 
parts in their URL are not affected, since there are other CGI scripts 
in the /bin directory that are used for TWiki operation, and the /pub 
directory contains images and other web-accessible attachments.

There is a document on the TWiki site which deals with this, but it 
assumes the TWiki is setup is the mentioned "twiki" subdirectory. I have 
tried modifying this to remove the twiki subdirectory, but it is not 
working. Here is the unmodified mod_rewrite rule from this document:

<quote>
RewriteEngine on

# If we used a topic or web name, rewrite it into viewauth
RewriteCond %{REQUEST_FILENAME} !/twiki/
RewriteCond /home/rnapier/public_html/twiki/data%{REQUEST_FILENAME}.txt
    -f [OR]
RewriteCond /home/rnapier/public_html/twiki/data%{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /twiki/bin/viewauth$1

# If we used a script name, rewrite it into twiki/bin
RewriteCond %{REQUEST_FILENAME} !/twiki/
RewriteCond %{REQUEST_FILENAME} ^/([^/]+)/
RewriteCond /home/rnapier/public_html/twiki/bin/%1 -f
RewriteRule ^/[^/]+/(.*)$ /twiki/bin/%1/$1 [PT]
</quote>

Note that the RewriteCond's are not broken up like that, it is only a 
result of my email client wrapping them. Also note that as far as I can 
tell in TWiki, "view" and "viewauth" are synonymous.

I have attempted to modify the above to work without a 'twiki' 
subdirectory, dealing directly with the /pub and /bin directories. Below 
is my attempt, in the context of my VirtualHost config in my httpd.conf 
file. The mod_rewrite config is at the bottom.

<VirtualHost 66.13.154.244:80>
         ServerAdmin webmaster@theoretic.com
         DocumentRoot /home/theoretic/test
         ServerAlias test.theoretic.com
         ServerName test.theoretic.com
#        User theoretic
#        Group theoretic
         ErrorLog /var/log/apache/test.theoretic.com-error.log
         TransferLog /var/log/apache/test.theoretic.com-access.log
         AddHandler cgi-script .cgi
         Options +ExecCGI
         #ProxyRequests On

         ScriptAlias /bin/ "/home/theoretic/test/bin/"
         Alias // "/home/theoretic/test/"
         <Directory "/home/theoretic/test/bin">
           Options +ExecCGI
           SetHandler cgi-script
           Allow from all
         </Directory>
         <Directory "/home/theoretic/test/pub">
           Options FollowSymLinks +Includes
           AllowOverride None
           Allow from all
         </Directory>
         <Directory "/home/theoretic/test/data">
           deny from all
         </Directory>
         <Directory "/home/theoretic/test/templates">
           deny from all
         </Directory>

         RewriteEngine on

         RewriteLog /home/theoretic/test/rewrite_log
         RewriteLogLevel 9

         # If we used a topic or web name, rewrite it into view
         RewriteCond %{REQUEST_FILENAME} !/bin/
         RewriteCond %{REQUEST_FILENAME} !/pub/
         RewriteCond /home/theoretic/test/data%{REQUEST_FILENAME}.txt -f
            [OR]
         RewriteCond /home/theoretic/test/data%{REQUEST_FILENAME} -d
         RewriteRule ^(.*)$ /bin/viewauth$1

         # If we used a script name, rewrite it into twiki/bin
         RewriteCond %{REQUEST_FILENAME} !/bin/
         RewriteCond %{REQUEST_FILENAME} !/pub/
         RewriteCond %{REQUEST_FILENAME} ^/([^/]+)/
         RewriteCond /home/theoretic/test/bin/%1 -f
         RewriteRule ^/[^/]+/(.*)$ /bin/%1/$1 [PT]
</VirtualHost>

After restarting Apache, I try it out by visiting the URL 
http://test.theoretic.com/Main/Home (which is the home page and should 
rewrite to http://test.theoretic.com/bin/view/Main/Home). I get an error 
404 and the following in the rewrite_log file:

209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) init rewrite 
engine with requested uri /Main/Home
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (3) applying 
pattern '^(.*)$' to uri '/Main/Home'
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/Main/Home' pattern='!/bin/' => matched
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/Main/Home' pattern='!/pub/' => matched
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/home/theoretic/test/data/Main/Home.txt' pattern='-f' => matched
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) rewrite 
/Main/Home -> /bin/viewauth/Main/Home
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (3) applying 
pattern '^/[^/]+/(.*)$' to uri '/bin/viewauth/Main/Home'
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/bin/viewauth/Main/Home' pattern='!/bin/' => not-matched
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) local path 
result: /bin/viewauth/Main/Home
209.26.25.155 - - [22/Dec/2002:12:52:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (1) go-ahead with 
/bin/viewauth/Main/Home [OK]

Everything seems to go fine, but still that 404. Now I try the full URL 
of http://test.theoretic.com/bin/view/Main/Home, and TWiki treats it 
like URL http://test.theoretic.com/view/Home (Note it is missing the 
'bin' and 'Main' parts from the URL). This returns an error in TWiki, 
since there is no category called 'Home' (it is supposed to be 'Main'). 
That produced this in the rewrite_log file:

209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) init rewrite 
engine with requested uri /Main/Home
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (3) applying 
pattern '^(.*)$' to uri '/Main/Home'
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/Main/Home' pattern='!/bin/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/Main/Home' pattern='!/pub/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/home/theoretic/test/data/Main/Home.txt' pattern='-f' => matched
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) rewrite 
/Main/Home -> /bin/viewauth/Main/Home
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (3) applying 
pattern '^/[^/]+/(.*)$' to uri '/bin/viewauth/Main/Home'
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/bin/viewauth/Main/Home' pattern='!/bin/' => not-matched
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) local path 
result: /bin/viewauth/Main/Home
209.26.25.155 - - [22/Dec/2002:13:05:25 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (1) go-ahead with 
/bin/viewauth/Main/Home [OK]

209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) init rewrite 
engine with requested uri /bin/view/Main/Home
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (3) applying 
pattern '^(.*)$' to uri '/bin/view/Main/Home'
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/bin/view/Main/Home' pattern='!/bin/' => not-matched
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (3) applying 
pattern '^/[^/]+/(.*)$' to uri '/bin/view/Main/Home'
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/bin/view/Main/Home' pattern='!/bin/' => not-matched
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (1) pass through 
/bin/view/Main/Home
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (2) init rewrite 
engine with requested uri /Main/Home
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (3) applying 
pattern '^(.*)$' to uri '/Main/Home'
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/Main/Home' pattern='!/bin/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/Main/Home' pattern='!/pub/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/home/theoretic/test/data/Main/Home.txt' pattern='-f' => matched
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (2) rewrite 
/Main/Home -> /bin/viewauth/Main/Home
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (3) applying 
pattern '^/[^/]+/(.*)$' to uri '/bin/viewauth/Main/Home'
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/bin/viewauth/Main/Home' pattern='!/bin/' => not-matched
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (2) local path 
result: /bin/viewauth/Main/Home
209.26.25.155 - - [22/Dec/2002:13:05:31 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (1) go-ahead with 
/bin/viewauth/Main/Home [OK]

209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) init rewrite 
engine with requested uri /oops/Home/Home
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (3) applying 
pattern '^(.*)$' to uri '/oops/Home/Home'
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/oops/Home/Home' pattern='!/bin/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/oops/Home/Home' pattern='!/pub/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/home/theoretic/test/data/oops/Home/Home.txt' pattern='-f' => 
not-matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/home/theoretic/test/data/oops/Home/Home' pattern='-d' => not-matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (3) applying 
pattern '^/[^/]+/(.*)$' to uri '/oops/Home/Home'
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/oops/Home/Home' pattern='!/bin/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/oops/Home/Home' pattern='!/pub/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/oops/Home/Home' pattern='^/([^/]+)/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (4) RewriteCond: 
input='/home/theoretic/test/bin/oops' pattern='-f' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) rewrite 
/oops/Home/Home -> /bin/oops/Home/Home
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8243cc4/initial] (2) forcing 
'/bin/oops/Home/Home' to get passed through to next API URI-to-filename 
handler

209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (2) init rewrite 
engine with requested uri /Home/Home
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (3) applying 
pattern '^(.*)$' to uri '/Home/Home'
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/Home/Home' pattern='!/bin/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/Home/Home' pattern='!/pub/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/home/theoretic/test/data/Home/Home.txt' pattern='-f' => not-matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/home/theoretic/test/data/Home/Home' pattern='-d' => not-matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (3) applying 
pattern '^/[^/]+/(.*)$' to uri '/Home/Home'
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/Home/Home' pattern='!/bin/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/Home/Home' pattern='!/pub/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/Home/Home' pattern='^/([^/]+)/' => matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (4) RewriteCond: 
input='/home/theoretic/test/bin/Home' pattern='-f' => not-matched
209.26.25.155 - - [22/Dec/2002:13:05:35 -0600] 
[test.theoretic.com/sid#80bb7f4][rid#8216134/subreq] (1) pass through 
/Home/Home

I have tried many various mod_rewrite setups over the past 2 days, 
tweaking and modifying different aspects. All have failed and at best 
produced similar results as above. At worst, they always return error 404s.

Again, apologies for the long post and lots of data. I'm hoping it will 
help someone much more experienced in mod_rewrite than I am see the problem.

-- 
     /\  Adam Theo, Age 23, Tallahassee FL USA
    //\\   Email & Jabber: theo@theoretic.com
   //  \\  Cell: (850) 567 1138
=//====\\=
//  ||  \\  Theoretic Solutions: http://www.theoretic.com
     ||         "Building Ideas by Bringing them Together"
     ||      Jabber Protocol: http://www.jabber.org
     ||         "The Next Generation Communications Protocol"
     ||  "A Free-Market Socialist Patriotic American Buddhist"


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message