Forum Moderators: phranque

Message Too Old, No Replies

Rewrite challenge

Subdomain redirect driving me crazy

         

Xoverride

2:01 pm on Jan 15, 2008 (gmt 0)

10+ Year Member



For the last week i've been nonstop working to get a redirect working. What I want is that these examples get redirect using a proxy/ajp I created.

The examples:
tim.example.com -> should be redirected
www.tim.example.com -> should be redirected

So I have tried like a million of redirect combinations, but none of them seem to work with both examples. In the end I thought it worked but I got an Apache error stating an infinite proxy loop.

If you now what to fill in the lines below, you are my hero :)

RewriteEngine on

# rewrite rule
------ THESE DO NOT WORK, WHAT SHOULD THEY BE? ------------

RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com [NC]
RewriteRule ^(.*) http://localhost/example/account.form?account=%1 [P]

-------------------------------------------------------------

<IfModule mod_proxy.c>

<Proxy /index.html >
Order deny,allow
Deny from all
</Proxy>

<Proxy /example >
Order deny,allow
Deny from all
</Proxy>

ProxyPass /example ajp://localhost:8009/example/
ProxyPassReverse /example ajp://localhost:8009/example/

</IfModule>

[edited by: jatar_k at 2:37 pm (utc) on Jan. 15, 2008]

[edited by: jdMorgan at 2:44 pm (utc) on Jan. 15, 2008]
[edit reason] please use example.com [/edit]

jdMorgan

2:46 pm on Jan 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where is this code located -- httpd.conf or .htaccess?
Do you have any other RewriteRules that work?
(If not, try a simple redirect to google.com to test.)

Jim

Xoverride

2:56 pm on Jan 15, 2008 (gmt 0)

10+ Year Member



It is located in httpd.conf

I had several rewrite rules that did work. They just do not work well enough.

If you know how to rewrite the examples in my first post, please let me know.

jdMorgan

8:01 pm on Jan 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com [NC]
RewriteRule ^/ ajp://localhost:8009/example/account.form?account=%2 [P]

I'm not sure what your DNS or hosts file setup is. If this still loops, you can add a RewriteCond to stop it:

RewriteCond %{SERVER_PORT} !^8009$

Jim

Xoverride

9:02 am on Jan 17, 2008 (gmt 0)

10+ Year Member



I used this code that I got from someone and that worked! Thanks for your input anyway's . I don't know if your code works, but this is working for me now:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule .* http://www.example.com/example/exampaccount.form?account=%1 [P,L]

Thanks again

[edited by: engine at 2:17 pm (utc) on Jan. 17, 2008]

[edited by: jdMorgan at 3:00 pm (utc) on Jan. 17, 2008]
[edit reason] examplified [/edit]

phranque

1:22 pm on Jan 17, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



by the way, welcome to WebmasterWorld [webmasterworld.com], Xoverride!

jdMorgan

3:03 pm on Jan 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you'll find that "account" is always being set to "www" when it is set...

Use "%2" in the RewriteRule substitution URL to correct this.

Jim