Forum Moderators: phranque

Message Too Old, No Replies

Desperate Help!

         

freak13211

3:36 pm on Jul 31, 2007 (gmt 0)

10+ Year Member



Here is what I have so far..

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule ^hcupload/$ http://www.example.com/hello/upload\.cgi [L]
RewriteRule ^$ domaincake/ [L]
RewriteRule (.*) domaincake/$1 [L]
</ifModule>

Basically, I want for everyone going to www.example.com to be redirected into the domaincake folder on my server. However, when someone goes to www.example.com/hcupload I want them redirected to http://www.example.com/hello/upload\.cgi (only in this scenario though). I seem to be able to get this working when I take away the redirection to the domaincake folder but as soon as I include both at the same time, it won't work.. I think its wanting to redirect my www.example.com/hcupload into the domaincake folder. Please help, I've spent almost 2 days on this :( I hope its simple - I am a newb at regular expression. Thanks

[edited by: jdMorgan at 3:16 am (utc) on Aug. 1, 2007]
[edit reason] example.com [/edit]

g1smd

10:01 pm on Jul 31, 2007 (gmt 0)

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



All of those are rewrites, not redirects.

What do you want, a redirect or a rewrite?

freak13211

11:29 pm on Jul 31, 2007 (gmt 0)

10+ Year Member



Wow.. your completely right, I want to redirect all of them not rewrite.. I've looked around on the net and can't really tell the difference - how would I change this?
many thanks :)

g1smd

11:58 pm on Jul 31, 2007 (gmt 0)

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



A redirect has a [R=301] in it and this is what forces the browser to request the new URL in a new HTTP transaction.

A rewrite simply fetches the content from filepath "B" when asked for URL "A" without ever divulging what filepath "B" actually is.

freak13211

12:53 am on Aug 1, 2007 (gmt 0)

10+ Year Member



Thanks for helping me understand that but... :( ..

This is what I want to happen:

www.example.com/hcupload/ -> http://www.example.com/hello/upload.cgi

www.example.com (or www.domain.com/anything else) -> www.example.com/domaincake

So in all cases redirect(or rewrite) to the domaincake folder EXCEPT when www.domain.com/hcupload is called.

The problem I think is that it thinks that www.example.com/hcupload/ is trying to redirect ALSO to BOTH www.example.com/domaincake AND www.example.com/hello/upload.cgi (thats my guess)

I get a 404 error when I try to accesss the CGI script through www.example.com/hello/upload.cgi AND www.example.com/hcupload/

I tried to be as clear as possible, any help would be SO MUCH appreciated!

Ahh the wonders of learning...

[edited by: jdMorgan at 3:17 am (utc) on Aug. 1, 2007]
[edit reason] example.com [/edit]

jdMorgan

3:22 am on Aug 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a RewriteCond to prevent the double redirect, and eliminate the redundant third rule.

RewriteEngine on
#
RewriteRule ^\.htaccess$ - [F]
#
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule ^hcupload/$ http://www.example.com/hello/upload.cgi [R=301,L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
[b]RewriteCond $1 [i][/i]!^hello/upload\.cgi$[/b]
RewriteRule (.*) http://www.example.com/domaincake/$1 [R=301,L]

Not sure why you're testing for the domain, but I added provisions for the non-www version and included the domain test in both rules for consistency.

Also not sure why you're using external redirects, which require a second HTTP request, and expose the new/real URL-path to the client.

Jim

[edited by: jdMorgan at 3:23 am (utc) on Aug. 1, 2007]

g1smd

7:28 pm on Aug 1, 2007 (gmt 0)

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



A redirect takes you to the new URL, and you see the new URL in the browser.

A rewrite fetches the content from elsewhere without showing you where it came from.

Does that make it more clear in your decision as to whether you need a redirect or a rewrite?