Forum Moderators: phranque

Message Too Old, No Replies

Rewrite rule subdomain to dynamic page

         

Lastwords

11:48 am on Sep 17, 2007 (gmt 0)

10+ Year Member



I know there is already a post about this, but I'm stuck and would appreciate any help with my rewrite rules, as shown below.

I'm trying to redirect (302), from a subdomain to a dynamic page.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com?$
RewriteRule ^$ /variable.php?ID=$555 [L]

And I've tried this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$
RewriteRule ^(.*)$ [subdomain.domain.com...] [R=301,L]

Any ideas on where I'm going wrong?

jdMorgan

1:12 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not enough info here...

Do you have other working RewriteRules in this file?

Did you completely flush your browser cache before testing after adding and/or changing the code?

What URL did you test?

What were the results?

How did those results differ from what you expected?

Do you wish to rewrite all pages in the subdomain, or just the 'index' page?

Do you want a redirect (changes the browser address bar) or an internal rewrite (which does not)?

Jim

Lastwords

1:33 pm on Sep 17, 2007 (gmt 0)

10+ Year Member



Thanks for getting back to me, here are the answers as best I can answer them:

1. There arent any other rewrite rules I can see in the httpd.conf. Just redirects.

2. Yes

3/4. I tested the subdomain, but it just went to the default website index.html. So it looked like it was redirecting like this: go to subdomain.domain.com redirects to subdomain.domain.com/index.html?ContentType=frontpage& etc. This is the same as when you go to www.domain.com, it redirects to www.domain.com/index.html?ContentType=frontpage& etc.

5. I want subdomain.domain.com to go to subdomain.domain.com/variable.php?ID=$555

6. Just the index page.

7. I believe I want a redirect (change the address bar), so I dont know if I've gone down the wrong path...

g1smd

11:28 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you want to have a redirect then you need [R=301] in the code.

Avoid a 302 redirect [R] or [R=302]. That is looking for trouble.

Your very first example was for a rewrite, not a redirect.

jdMorgan

12:19 am on Sep 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is usual, when 'pointing' URLs to a script, to use an internal rewrite.

Jim