Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite help

         

Ayres

11:14 pm on Aug 8, 2004 (gmt 0)

10+ Year Member



Can someone give me an hand, i'm having an hard time to figure this out.

Forwarding any request from:

[domain.net...]

to

[folder.domain.net...]

where

$1 is a variable forwarding any file request in question, including all parameters passed to PHP files.

That means, for example, that

[domain.net...]

has to be forwarded or rewritten as

[folder.domain.net...]

and not merely as

[folder.domain.net...]

(which will display nothing)

Can someone give me and hand? i would be glad. Thanks in Advance.

[edited by: jdMorgan at 2:08 am (utc) on Aug. 10, 2004]
[edit reason] Removed specific domain name [/edit]

jdMorgan

7:04 pm on Aug 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ayres,

Welcome to WebmasterWorld [webmasterworld.com]!

Post your code, and we'll take a look. As stated in our Charter, we'll help you get it working, but can't write it for you.

Jim

Ayres

8:59 pm on Aug 9, 2004 (gmt 0)

10+ Year Member



Well, sure, i'm just in despair because i've tried a million of them and nothing, it just doesn't parse the parameters.

This one seems to be the most correct of them, IMO.

RewriteCond %{HTTP_HOST}!^folder\.domain\.net [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule ^/(.*) [folder.domain.net...] [L,R]

jdMorgan

9:10 pm on Aug 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm...

What you have should work, but maybe some other rule is dropping the query string.
How about this?


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^folder\.domain\.net [NC]
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^/(.*) http://folder.domain.net/$1?%1 [R=301,L]

Jim

Birdman

12:25 am on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey there. I was looking at this earlier and had to run out. This is what I had come up with(actually I forgot the NC and R flags):

RewriteEngine on
RewriteCond %{QUERY_STRING} (.*) [NC]
RewriteRule ^folder/(.*)$ ht-p://folder.domain.net?%1 [R=301,L]

Why not just put the rules in the root .htaccess folder of site A and forget the HTTP_HOST conditional?

Oh, welcome from me as well!

Birdman

Ayres

10:43 am on Aug 10, 2004 (gmt 0)

10+ Year Member



Thank you guys so much for the help.

However the code you provided have done exactly the same.

I just can't understand it, everything i've tried, it never parses the parameters, whatever is beyond que question mark, simply vanish.

jdMorgan

2:47 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suspect you've got another redirect involved at a higher level (like in the hosting set-up) that is removing the query string.

Try following the redirect path by using the server headers checker [webmasterworld.com]. Each time you get an external redirect response, submit the URL that it says it redirected to back into the headers checker, and follow it through step-by-step. Somewhere in the process, you'll see the query string drop off, and that will give you an indication of where to look for the problem.

Jim

Ayres

4:40 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



I entered: [domain.net...]

and this was what i got:

HTTP/1.1 302 Found
Date: Tue, 10 Aug 2004 16:36:04 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_fastcgi/2.2.10 mod_jk/1.2.0 mod_perl/1.24_01 PHP/4.2.2 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b
Location: [folder.domain.net...]
Connection: close
Content-Type: text/html; charset=iso-8859-1

(I switched the real domain, folder and file name to keep the privacy, once again, thank you so much for the help.)

jdMorgan

5:07 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, the code we've been working on here does a 301 redirect, and what you show in the headers check results is a 302. So the question is, who or what is doing that?

If you have some kind of funky 'domain pointing' or a shared hosting account (such as mapping subdomains to subdirectories of a common account), and that's not set up right, then that could be the cause. If you are not aware of any redirection that *should* be taking place before your .htaccess file is reached, then I'm afraid you'll have to dig through your DNS setup and your hosting account setup to find this.

Jim

Ayres

4:32 pm on Aug 11, 2004 (gmt 0)

10+ Year Member



so, are you saying that if i change the 301 redirect in the mod_rewrite to a 302, it should work?

I don't think there is any problem with that, because i've used other codes in the past and they worked, something like this:

RewriteCond %{HTTP_HOST} [^.]*domain\.net$
RewriteRule ^(.*)$ /folder/$1

Worked very good, such as this one:

RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?domain.net/.*$ [NC]
RewriteRule \.(gif¦jpg¦jpeg¦png)$ [domain.net...] [R,L]

And they both worked.

What should i do?

jdMorgan

1:51 pm on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> so, are you saying that if i change the 301 redirect in the mod_rewrite to a 302, it should work?

No, not at all. I'm saying that for some reason, you are getting a 302 redirect, and it is not the result of the code we've been discussing. So why are you getting a 302? You need to find out where that is happening and why in order to fix this problem.

Sometimes, people that use "domain pointing" services end up with a 302 redirect on every access to their site, and it slows everything down, screws up their serach engine listings, and generally causes problems. Make sure that's not the case here.

Jim