difficult mod_rewrite question

I have a blogging script that takes GET input.   an example might be ?u in the first example.  

user.domain.com shoudl be rewritten to user.domain.com?u=user for instance.
I have been told that this code would function with my site but its not.   I have checked that mod_rewrite is working




RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI}^([^.]+)\.DOMAIN\.COM(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^page(\d+)/?$ /index.php?u=%1&page=$1 [L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI}^([^.]+)\.DOMAIN\.COM(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^profile/?$ /profile.php?u=%1 [L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI}^([^.]+)\.DOMAIN\.COM(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^archive/([^/]+)/([^/]+)/?$ /archive.php?u=%1&y=$1&m=$2 [L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI}^([^.]+)\.domain\.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^archive/([^/]+)?/?$ /archive.php?u=%1 [L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI}^([^.]+)\.domain\.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^archive/?$ /archive.php?u=%1 [L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI}^([^.]+)\.domain\.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^(\d+)/?$ /entry.php?u=%1&e_id=$1 [L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI}^([^.]+)\.domain\.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^$ /index.php?u=%1 [L]
LVL 1
hibbidijiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

caterham_wwwCommented:
the original intention of your snipped was the following:

a request of user.domain.de/123.php points via DNS-Entry to / (root)
/.htaccess should rewrite this request internally to /user/123.php

=> write subdomains in subdirs located at the main domain
domain.com => /
sub.domain.com => /sub/ this is equal to domain.com/sub/

is this the case for you, too?

If NOT (what seems to be the case: "user.domain.com shoudl be rewritten to user.domain.com?u=user") you can use
for .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{QUERY_STRING} !^u=
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com
RewriteRule ^$ /?u=%2 [L]

for httpd.conf (outside <Directory>)

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{QUERY_STRING} !^u=
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com
RewriteRule ^/$ /?u=%2 [L]
0
ahoffmannCommented:
you have syntax errors in most of your directives
RewriteCond cannot contain back-references like $1
RewriteRule uses $1, $2, etc. as back.reference and not %1, %2, etc.
0
hibbidijiAuthor Commented:
Ahoffman,
I'm going to post a WORKING htaccess instead and ask for help changing how it works:

my application USUALLY takes a url format like this:

domain.com/?u=username&p=25
(p is page)

I have written a php include that sets $_GET["u"] based on the subdomain:

http://username.domain.com
This will set ?u for me (thanks to my code)   In the htaccess below you will see that it has gone halfway, and is rewriting urls to this format:
http://www.domain.com/username/25
This would set $u and $p (as 25)
Further vars are set as well.   I can change how my script links to itself with no problem including the order of args that are passed.


RewriteEngine On
Options +Followsymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/page(\d+)/?$ /index.php?u=$1&page=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/profile/?$ /profile.php?u=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/archive/([^/]+)/([^/]+)/?$ /archive.php?u=$1&y=$2&m=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/archive/([^/]+)?/?$ /archive.php?u=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/archive/?$ /archive.php?u=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /entry.php?u=$1&e_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /index.php?u=$1 [L]

In some examples such as the profile request, I would like it to be http://username.domain.com/profile
In these instances, where there is only one argument, and its username, (get-u) I can fix this with my hack.  Other instances such as the archive, I would like it to be http://username.domain.com/archive/2004/12   (for december 2004)

suggestions?

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

ahoffmannCommented:
>  such as the profile request,

RewriteRule ^([^/]+)/profile  http://$1.domain.com/profile.php?u=$1 [L]
# added   http://username.domain.com/  /not shure if this is what you want (assuming that username is $1)
# removed the trailing /?$ 'cause I assume that noone gives such an URL

RewriteRule ^([^/]+)/archive/([^/]+)?/?$ http://$1.domain.com/archive.php?u=$1 [L]
# not shure what you want here, missing an example
0
hibbidijiAuthor Commented:
allow me to elaborate.

I dont need the subdomain var to be assigned.   I am grabbing this with php.   what I am primarily concerned with is a framework to build on.

archive.php takes 3 arguments. $u (user)   $y (year) and $m (month)
I have already taken care of $u
I want a line that will look for all requests for  domain.com/archive/2004/12 and rewrite it into:  archive.php?y=2004&m=12

Using this information, I can make the rest of the lines I believe
0
ahoffmannCommented:
RewriteRule ^/archive/([\d]+)/([\d]+)/?$ /archive.php?y=$1&m=$2 [L]

# accordiong your example, I'don't see where username is comming from
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hibbidijiAuthor Commented:
when archive.php is loaded, "subdomainhack.php" is loaded.   it contains code that parses the URL and assigns $_GET["u"] from the subdomain
I will try this now
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.