RewriteMap not working

Using a single web hosting account to host multiple sites

RewriteMap not working

Postby cavergary » Wed Mar 25, 2009 8:41 pm

I'm trying to get the following code to work, however, Apache won't even start. I get the following error
The Apache service named reported the following error:
>>> RewriteRule: bad argument line '^/index.php?uid=The Apache service named' .

Code: Select all

ServerName wildcard.domain.com
   ServerAlias *.domain.com

RewriteEngine On             
   RewriteCond %{HTTP_HOST} !^www\.domain\.com
   RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
   RewriteMap stfuid txt:"c:/domain_uid.txt"
   RewriteRule ^/index.php?uid=%1
      {stfuid:$1| http://www.domain.com/test.php }


I'm trying to rewrite the url in this manner,

username.domain.com --> username.domain.com/index.php?uid=01

the map file is located at c:/domain_uid.txt and is in this format:

username 01
username1 02


Any help would be appreciated! Thanks!
cavergary
 
Posts: 7
Joined: Wed Mar 25, 2009 8:23 pm

Postby richardk » Thu Mar 26, 2009 9:36 am

RewriteRules match the URL in the address bar of the browser.
You cannot use variables/backreferences in regular expressions.

Try
Code: Select all
<VirtualHost *:80>
   ServerName wildcard.example.com
   ServerAlias *.example.com

   Options +FollowSymLinks

   RewriteEngine On

   RewriteMap stfuid txt:"c:/domain_uid.txt"

   RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
   RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
   RewriteRule ^$ /index.php?uid=${stfuid:%1|user_not_found} [QSA,PT,L]
</VirtualHost>

What should happen when you visit user.example.com/something?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Thank... still working out the kinks here

Postby cavergary » Fri Mar 27, 2009 7:57 pm

Thanks for your suggestion richardk.

I keep thinking this should be simple, then it's not.

I used your code and Apache still will not start. This is the really frustrating part...

the file is in c:/stf_uid.txt. I also placed a copy in c:/website/
The error is

>>> RewriteMap: bad path to txt map: "c:/websites/stf_uid.txt"

I can open the txt file in notepad w/o grief. The permissions are open as far as I can tell.

On my dev box I'm running Xampp in c:/program files/xampp and the config is in C:\Program Files\xampp\apache\conf\extra\httpd-vhosts.conf"

When I change the httpd-vhosts.conf I see the changes in the event logs, so I know it is being read and refreshed.

I don't get it....

Here is what I'm trying to accomplish, perhaps I'm barking up the wrong tree...

Here is what I'm trying to accomplish

username.domain.com --> username.domain.com w/cookie set with username's ID (UID)

Scenerio:

The client wants registered users to have a customized website for their consultants. When Apache is presented with username.domain.com some of the pages get custom content from a database based on their UID.

I have explored setting a cookie with the UID which is later called by a script to query the database based on the UID to present custom content.

[/quote]
cavergary
 
Posts: 7
Joined: Wed Mar 25, 2009 8:23 pm

Postby richardk » Sat Mar 28, 2009 8:34 am

Try
Code: Select all
   RewriteMap stfuid txt:c:/domain_uid.txt
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

One step forward

Postby cavergary » Sat Mar 28, 2009 3:42 pm

I tried your code, but it failed again.

Now, this makes little to no sense to me, but I got apache to start with this code
Code: Select all
RewriteMap stfuid txt:c:/domainuid.txt

Notice the differences here are, as you suggested, no quotes - and the underbar is gone from the file name. The underbar seems to have been the other half of the problem!

Thanks for sticking with me here! Now that Apache is running, I can do some testing...
cavergary
 
Posts: 7
Joined: Wed Mar 25, 2009 8:23 pm

Postby richardk » Sat Mar 28, 2009 6:29 pm

Code: Select all
^$

should be
Code: Select all
^/$


What should happen when you visit user.example.com/something?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Almost there!!!

Postby cavergary » Sat Mar 28, 2009 8:22 pm

The Rewrite map is working great now.

My code looks like this:
Code: Select all
RewriteMap stfuid txt:c:/stfuid.txt
   RewriteCond %{HTTP_HOST} !^www\.stf\.com
   RewriteCond %{HTTP_HOST} ([^.]+)\.stf\.com$ [NC]
   RewriteRule ^(.*)$ /cookie.php?uid=${stfuid:%1|user_not_found}[QSA,PT,L]


But there is a problem, the query string is getting split off.

This is the Rewritelog
(2) init rewrite engine with requested uri /
(3) applying pattern '^(.*)$' to uri '/'
(4) RewriteCond: input='aflyer.stf.com' pattern='!^www\.stf\.com' => matched
(4) RewriteCond: input='aflyer.stf.com' pattern='([^.]+)\.stf\.com$' [NC] => matched
(5) map lookup OK: map=stfuid[txt] key=aflyer -> val=13
(2) rewrite '/' -> '/cookie.php?uid=13[QSA,PT,L]'
(3) split uri=/cookie.php?uid=13[QSA,PT,L] -> uri=/cookie.php, args=uid=13[QSA,PT,L]
(2) local path result: /cookie.php
(2) prefixed with document_root to C:/Documents and Settings/Gary/My Documents/Websites/STF/cookie.php
(1) go-ahead with C:/Documents and Settings/Gary/My Documents/Websites/STF/cookie.php [OK]


It looks like it build the correct uri then splits off the query string even though the [QSA] flag is set.
cavergary
 
Posts: 7
Joined: Wed Mar 25, 2009 8:23 pm

Postby richardk » Sun Mar 29, 2009 9:22 am

You are missing a space before the flags so they are not processed.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteMap stfuid txt:c:/stfuid.txt

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /cookie.php?uid=${stfuid:%1|user_not_found} [QSA,PT,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Not sure ..

Postby cavergary » Mon Mar 30, 2009 7:26 pm

I have tried a dozen different arrangements of this code, but none of them are stopping the SPLIT URI thing. Curiously I get the same results in the log file with or without the [QSA] flag set. My Code
Code: Select all
RewriteEngine On             
   
RewriteMap stfuid txt:c:/stfuid.txt
   RewriteCond %{HTTP_HOST} !^www\.stf\.com [NC]
   RewriteCond %{HTTP_HOST} ([^.]+)\.stf\.com$ [NC]
   RewriteRule ^(.*)$ /cookie.php?uid=${stfuid:%1|user_not_found} [QSA,PT,L]

Result:
(2) init rewrite engine with requested uri /
(3) applying pattern '^(.*)$' to uri '/'
(4) RewriteCond: input='aflyer.stf.com' pattern='!^www\.stf\.com' [NC] => matched
(4) RewriteCond: input='aflyer.stf.com' pattern='([^.]+)\.stf\.com$' [NC] => matched
(6) cache lookup FAILED, forcing new map lookup
(5) map lookup OK: map=stfuid[txt] key=aflyer -> val=13
(2) rewrite '/' -> '/cookie.php?uid=13'
(3) split uri=/cookie.php?uid=13 -> uri=/cookie.php, args=uid=13
(2) local path result: /cookie.php
(2) prefixed with document_root to C:/Documents and Settings/Gary/My Documents/Websites/STF/cookie.php
(1) go-ahead with C:/Documents and Settings/Gary/My Documents/Websites/STF/cookie.php [OK]
cavergary
 
Posts: 7
Joined: Wed Mar 25, 2009 8:23 pm

Postby richardk » Tue Mar 31, 2009 8:07 am

Are you actually losing the query string or are you just worrying about the RewriteLog?

Code: Select all
(3) split uri=/cookie.php?uid=13 -> uri=/cookie.php, args=uid=13

That's supposed to happen.
Code: Select all
RewriteRule ^abc2$ /index.php?1=2 [QSA,L]

... (2) init rewrite engine with requested uri /abc2
... (1) pass through /abc2
... (3) [perdir E:/Server/www/example/] strip per-dir prefix: E:/Server/www/example/abc2 -> abc2
... (3) [perdir E:/Server/www/example/] applying pattern '^abc2$' to uri 'abc2'
... (2) [perdir E:/Server/www/example/] rewrite 'abc2' -> '/index.php?1=2'
... (3) split uri=/index.php?1=2 -> uri=/index.php, args=1=2&def=ghi
... (1) [perdir E:/Server/www/example/] internal redirect with /index.php [INTERNAL REDIRECT]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 23 guests

cron