Forum Moderators: phranque

Message Too Old, No Replies

REWRITE in httpd.conf ? Help please dear all! :D

         

rezinprince

9:06 am on Jun 16, 2010 (gmt 0)

10+ Year Member



Hi to all!
im really-really-really newbie at this 'rewrite' things

at httpd.conf i wrote this code :

NameVirtualHost www.vhost.com
<VirtualHost www.vhost.com>
ServerName www.vhost.com

ProxyPreserveHost On
ProxyRequests Off

ProxyPass / http://10.10.10.5/
ProxyPassReverse / http://10.10.10.5/


RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+\.com) [NC]
RewriteRule ^/(.*)http://www.%1/$1 [R=301,L]

</VirtualHost>


At index.php (directoryindex) i wrote this code:

if ($url=="localhost:8787" ) //check address
{
header( 'Location: http://www.vhost.com:8787/test.html' );
}


The currentsituation is:
WHEN people input URL : "http://localhost:8787/"
THE result will redirect : "http://www.vhost.com:8787/test.html"

But what i really want AND my BOSS wishis:
WHEN people input URL : "http://localhost:8787/"
THE page will be the result of : "http://www.vhost.com:8787/test.html"
WITH the URL addres : "http://localhost:8787/test.html"

Can I do that? Can we do that, Sir , Madam, Master?

How do i make it works?
Thanks to you all! Really thanks in advance!

[edited by: jdMorgan at 2:19 pm (utc) on Jun 17, 2010]
[edit reason] De-linked [/edit]

rezinprince

10:32 am on Jun 16, 2010 (gmt 0)

10+ Year Member



UPDATE my code in httpd.conf:

NameVirtualHost www.vhost.com
<VirtualHost www.vhost.com>
ServerName www.vhost.com
ServerAdmin bobby@telkomsel.co.id

ProxyPreserveHost On
ProxyRequests Off

ProxyPass / http://10.10.10.5/
ProxyPassReverse / http://10.10.10.5/

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.vhost.com:8787
RewriteRule ^.*$http://localhost:8787/ [R=301,L]

</VirtualHost>

it doesn't work... any one willing to help me pleasee ...

Thanks in advance

[edited by: jdMorgan at 2:20 pm (utc) on Jun 17, 2010]
[edit reason] De-linked [/edit]

rezinprince

12:01 pm on Jun 16, 2010 (gmt 0)

10+ Year Member



Update my latest code, still doesn't know how...

Please help anyone ...

1st Try and failed:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.vhost\.com:8787
RewriteRule ^$http://localhost:8787/ [L]


2nd try and failed

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.vhost\.com
RewriteRule ^$http://localhost:8787/ [L]


3rd try and failed

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.vhost\.com:8787
RewriteRule ^$/test.html [L]


Just give me any input...

Thanks in advance...

jdMorgan

1:32 pm on Jun 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please be aware that many of the contributors to this forum may be asleep while you are at work... This is a forum, not "instant messaging"...

You have posted a lot of code, but no information about the problem. Please organize your process:

How did you test? What URLs did you enter?
What was the expected result?
What was the actual result?
How did the actual result differ from your expectations?

Be aware that all requests will likely get reverse-proxied *before* the rewriterule can be executed. That is the only obvious clue I can give you. Look to <Location> or <Directory> containers to make the proxy invocation conditional if the ProxyPassReverse pattern cannot be made more specific.

Jim

rezinprince

3:21 am on Jun 17, 2010 (gmt 0)

10+ Year Member



Sorry dear jim, i was in a rush because of some pressure...
Question:
**How did you test?
Answer:
I wrote the URL address in browser : "http://www.vhost.com:8787/"
And the result still 'index.php'(directoryindex), along with URL didn't change into "http://localhost:8787/"

Question:
**What URLs did you enter?
Answer: "http://localhost:8787/"


Question:
**What was the expected result?
Answer:Page will be redirected and linked to "http://www.vhost.com:8787/test.html" (already succeess!),
BUT THE URL don't changes into "www.vhost.com" (Mission Objective!)

so my GOAL is:

URL input: "http://localhost:8787/"
output URL: "http://localhost:8787/..." or just "http://localhost:8787/"
output page: "test.html"


Question:
**What was the actual result?
Answer:
URL input: "http://localhost:8787/"
output URL: "http://www.vhost.com:8787/test.html"
output page: "test.html"


What must i do to make this happen?

Thanks in advance :)

rezinprince

3:40 am on Jun 17, 2010 (gmt 0)

10+ Year Member



Really sorry if my words make confuse...

I just wanna make sure, so there is no misundertanding.

What i expected is :
I redirect the URL : http://localhost:8787/
To URL: http://www.vhost.com:8787/test.html
but i want to rewrite/masking the redirect URL. So, the URL still http://localhost/

conclusion: Redirect YES, Rewrite/Mask URL YES.

Really sorry to make many post...

Thanks in advance for your help :D

[edited by: jdMorgan at 2:17 pm (utc) on Jun 17, 2010]
[edit reason] De-linked [/edit]

jdMorgan

2:23 pm on Jun 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One thing I don't understand here is: Where does the value of "vhost" come from. I see nothing in the requested URL to indicate any 'vhost' information.

Jim

rezinprince

6:20 pm on Jun 17, 2010 (gmt 0)

10+ Year Member



www.vhost.com is virtualhost created in httpd.conf, which already registered as DNS in etc hosts

And in directoryindex (index.php), I wrote this:
if ($url=="localhost:8787" ) //check address
{
header( 'Location: [vhost.com:8787...] );
}

What I expected is, after the page redirect succesfully, the url in the browser still old URL...

Thanks for your respons jim...

Really need help..

jdMorgan

12:46 am on Jun 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, the definition of a redirect is that it sends a response to the client with a new URL, saying, "Please ask for what you wanted again, using this new URL." This terminates the current HTTP transaction, and the client must begin a new one.

Rather than asking about code, I would advise asking about the right way to implement your entire plan, as the current implementation is flawed and cannot work as you desire.

Jim

rezinprince

3:13 am on Jun 18, 2010 (gmt 0)

10+ Year Member



Hmm...thanks for your comments and input... really helping a lot...

But is there no way at all?

What must i do? i will do anything necessary...

My goal is change the URL address in the browser after redirect...just that...

The purpose is: any visitor will not save the new URL, but the old URL...

Im pretty desperate... but really thanks jim :)

jdMorgan

5:22 am on Jun 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> My goal is change the URL address in the browser after redirect...just that...

This, by definition, is impossible.

The browser always shows the address of the URL it is fetching. If you redirect it to a new URL, it will show that URL.

As above, the whole plan is flawed, and I suggest a re-design.

You've got these tools:

External client redirects (mod_rewrite or PHP)
Internal URL-to-filepath-translation rewrites (mod_rewrite)
PHP file 'includes' (PHP)
Reverse proxy through-puts (mod_proxy or mod_rewrite)

Research what each of these terms means, and analyze how you could use it to achieve whatever your overall goal is. Tell the boss it is going to take at least one week to do this properly -- That is the estimate that I would give, assuming that you have to coordinate with other 'staff' and have a few meetings...

Jim

rezinprince

5:53 am on Jun 18, 2010 (gmt 0)

10+ Year Member



Just IF my boss can understand that...

Oke... i'll try my best...

thx Jim!

God Bless u

rezinprince

5:56 am on Jun 18, 2010 (gmt 0)

10+ Year Member



By the way,

I just wanna make sure, is it possible to make my GOAL accomplished with FRAMING method?

Sorry to ask again...

g1smd

10:11 am on Jun 18, 2010 (gmt 0)

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



Do not use frames.

Just don't.