You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Hank <he...@gmail.com> on 2008/04/21 01:42:34 UTC

[users@httpd] silent URL redirect/cloak with mod_rewrite

Hello All,

I've tried about 100 combinations and searched google over and over, but I
can't find nor figure out how to do this simple task.

I have one webserver with sites at:

/home/user/public_html/  ( http://basedomain.com site points here)
/home/user/public_html/siteA
/home/user/public_html/siteB

I have domain names like this:  http://domainA.com <http://domaina.com/> and
http://domainB.com <http://domainb.com/>

I want to *silently* redirect http://domainA.com <http://domaina.com/> to
/home/user/public_html/siteA
and http://domainB.com <http://domainb.com/> to
/home/user/public_html/siteB

Now keep in mind the literals "domainA" is not the same as the directory
name "siteA", and same for domainA/siteA.

I have found several ways to non-silently redirect
http://domainA.com<http://domaina.com/>to
http://basedomain/siteA, but that's not good enough.  It needs to be a
silent re-direct.

I realize I could do this with virtual domains if I had access to
httpd.conf, but I don't on this server.

Thanks,
-Hank

Re: [users@httpd] Search & Replace + Redirect with Mod_Rewrite?

Posted by Joshua Slive <jo...@slive.ca>.
On Tue, Apr 29, 2008 at 12:52 PM, Vik Rubenfeld <vi...@mindspring.com> wrote:
>
> I need to change the variable names in query strings. This is because I
> need to get two different supplier companies talking to each other. (One
> supplier uses variable names that the other supplier doesn't recognize).
>
> So I'm getting supplier A to send the URL to one of my domains, where I can
> change the variable names in the query string, and then redirect to the web
> site of supplier B.
>
> For example, I'd like to change:
>
> > http://www.my_domain_name.com/wsb.dll/s/12345?DDR2=test_2_data&DDR3=
> > test_3_data
>
> ...to:
>
> > https://supplier_B.com/wsb.dll/s/12345?wsb5=test_2_data&wsb6= test_3_data
>
> Here's my current mod rewrite code, which gives me a "Internal Server Error"
> message:
>
>
> > Options +FollowSymLinks
> > Options +Indexes
> > RewriteEngine On
> >
> > RewriteRule ^(.*)DDR2(.*)$ $1wsb5$2 [NC]
> >
> > RewriteRule ^(.*)DDR3(.*)$ $1wsb6$2 [NC,L]
> >
> > Redirect (.*)my_domain_name.com/wsb.dll/(.*) $supplier_B.com/wsb.dll/$2
>
> What is the correct way to do this?
>
> Thanks very much in advance to all for any info.

You'll want to start here:
http://wiki.apache.org/httpd/RewriteQueryString

Then you'll want to be sure to use the RewriteLog to debug.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Search & Replace + Redirect with Mod_Rewrite?

Posted by Vik Rubenfeld <vi...@mindspring.com>.
I need to change the variable names in query strings. This is because  
I  need to get two different supplier companies talking to each other.  
(One supplier uses variable names that the other supplier doesn't  
recognize).

So I'm getting supplier A to send the URL to one of my domains, where  
I can change the variable names in the query string, and then redirect  
to the web site of supplier B.

For example, I'd like to change:

 > http://www.my_domain_name.com/wsb.dll/s/12345?DDR2=test_2_data&DDR3=
 > test_3_data

...to:

 > https://supplier_B.com/wsb.dll/s/12345?wsb5=test_2_data&wsb6=  
test_3_data

Here's my current mod rewrite code, which gives me a "Internal Server  
Error" message:

 > Options +FollowSymLinks
 > Options +Indexes
 > RewriteEngine On
 >
 > RewriteRule ^(.*)DDR2(.*)$ $1wsb5$2 [NC]
 >
 > RewriteRule ^(.*)DDR3(.*)$ $1wsb6$2 [NC,L]
 >
 > Redirect (.*)my_domain_name.com/wsb.dll/(.*) $supplier_B.com/ 
wsb.dll/$2

What is the correct way to do this?

Thanks very much in advance to all for any info.

Re: [users@httpd] silent URL redirect/cloak with mod_rewrite

Posted by Hank <he...@gmail.com>.
I solved the problem.

I have in the .htaccess file in the root directory (../public_html/)

RewriteEngine On
RewriteCond  %{HTTP_HOST}   ^domainA.comt$
RewriteRule   ^(.*)$  /home/user/public_html/siteA/$1

but then in the /siteA subdirectory, I now have another .htaccess file with
only:

RewriteEngine Off

Then everything works perfectly!

Thanks to everyone for your suggestions.  It is possible to create a
"virtual" virtual named host without write access to httpd.conf on a shared
hosting environment.

-Hank

Re: [users@httpd] silent URL redirect/cloak with mod_rewrite

Posted by Hank <he...@gmail.com>.
On Mon, Apr 21, 2008 at 10:47 AM, Hank <he...@gmail.com> wrote:

>
> If the content is living on the same server as domainA.com (which it
> apparently is in this case), then you don't want to proxy. There is no
> need to create an additional HTTP request. You just instruct apache to
> grab the file directly. So you want something like
>
> >
> > RewriteCond  %{HTTP_HOST}   ^domainA.com$
> > RewriteRule   ^(.*)$  /home/user/public_html/siteA/$1
> >
> > If this doesn't work, tell us EXACTLY what happens: what do you see in
> > the browser, error_log, and access_log?
> >
>
>



I found part of the problem, but not how to solve it.

When configured as such:

RewriteCond  %{HTTP_HOST}   ^domainA.net$
RewriteRule   ^(.*)$  /home/user/public_html/siteA/$1 [L]


Apache is returning a 500 error.. the error_log shows:

"mod_rewrite: maximum number of internal redirects reached. Assuming
configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit
if neccessary."

I also found the httpd.conf on the server, and it doesn't seem to be doing
any other mod_rewrite stuff.

Why is it going into a recursive loop?

thanks.
-Hank

Re: [users@httpd] silent URL redirect/cloak with mod_rewrite

Posted by Hank <he...@gmail.com>.
If the content is living on the same server as domainA.com (which it
apparently is in this case), then you don't want to proxy. There is no
need to create an additional HTTP request. You just instruct apache to
grab the file directly. So you want something like

>
> RewriteCond  %{HTTP_HOST}   ^domainA.com$
> RewriteRule   ^(.*)$  /home/user/public_html/siteA/$1
>
> If this doesn't work, tell us EXACTLY what happens: what do you see in
> the browser, error_log, and access_log?
>

I tried exactly that, and I'm getting an Error 500 (Internal server error).
I'll have to do more testing to figure out exactly what the problem is later
this afternoon.  Thanks for the assistance.

-Hank

Re: [users@httpd] silent URL redirect/cloak with mod_rewrite

Posted by Joshua Slive <jo...@slive.ca>.
On Mon, Apr 21, 2008 at 10:04 AM, Hank <he...@gmail.com> wrote:
> n Mon, Apr 21, 2008 at 3:04 AM, Boyle Owen <Ow...@swx.com> wrote:

>
> >  understand you correctly, you have registered domainA and domainB and the
> domain names point to your server's IP in DNS. You want to map domainA to
> ../siteA and domainB to ../siteB. You don't have access to the server's
> httpd.conf directly and only have access to .htaccess files.
>
>  Owen,
>   Thanks for your response.. yes, that is exactly what I want to do, and
> yes, I meant proxying the requests and not redirecting them -- thanks for
> the clarification.
>
>  I've tried many combinations of the following, which I can get to work as a
> re-direct, but never a proxy:
>
> RewriteCond  %{HTTP_HOST}   ^domainA.com$
> RewriteRule   ^(.*)$  http://basedomain.com/siteA/$1   [P]
>
> WIth a [P] option, I get a 404 error.  With a [L] option, I get a redirect
> but the domain changes to basedomain.com/siteA and not domainA.com/.
>
> I've tried
>
> RewriteCond  %{HTTP_HOST}   ^domainA.com$
> RewriteRule   ^(.*)$  /home/user/public_html/siteA/$1  [P]
>
> with both [L] and [P] and it still won't work like I want it to.
>
> I guess I'm surprised I can't get mod_rewrite to silently proxy a call to
> domainA.com to basedomain.com/siteA .  I'll guess I'll write a little PHP
> script to do it for me if I can't get mod_rewrite to do it for me.

If the content is living on the same server as domainA.com (which it
apparently is in this case), then you don't want to proxy. There is no
need to create an additional HTTP request. You just instruct apache to
grab the file directly. So you want something like

RewriteCond  %{HTTP_HOST}   ^domainA.com$
RewriteRule   ^(.*)$  /home/user/public_html/siteA/$1

If this doesn't work, tell us EXACTLY what happens: what do you see in
the browser, error_log, and access_log?

If you still can't figure it out, you'll need to use the RewriteLog.
Since you only have access to .htaccess on the live server, you'll
need to setup a test server where you can manipulate httpd.conf in
order to activate the RewriteLog.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] silent URL redirect/cloak with mod_rewrite

Posted by Hank <he...@gmail.com>.
n Mon, Apr 21, 2008 at 3:04 AM, Boyle Owen <Ow...@swx.com> wrote:

>    ------------------------------
>  understand you correctly, you have registered domainA and domainB and the
> domain names point to your server's IP in DNS. You want to map domainA to
> ../siteA and domainB to ../siteB. You don't have access to the server's
> httpd.conf directly and only have access to .htaccess files.
>
>  Owen,
>
  Thanks for your response.. yes, that is exactly what I want to do, and
yes, I meant proxying the requests and not redirecting them -- thanks for
the clarification.

 I've tried many combinations of the following, which I can get to work as a
re-direct, but never a proxy:

RewriteCond  %{HTTP_HOST}   ^domainA.com$
RewriteRule   ^(.*)$  http://basedomain.com/siteA/$1   [P]
WIth a [P] option, I get a 404 error.  With a [L] option, I get a redirect
but the domain changes to basedomain.com/siteA and not domainA.com/.

I've tried

RewriteCond  %{HTTP_HOST}   ^domainA.com$
RewriteRule   ^(.*)$  /home/user/public_html/siteA/$1  [P]

with both [L] and [P] and it still won't work like I want it to.

I guess I'm surprised I can't get mod_rewrite to silently proxy a call to
domainA.com to basedomain.com/siteA .  I'll guess I'll write a little PHP
script to do it for me if I can't get mod_rewrite to do it for me.

thanks,

-Hank

RE: [users@httpd] silent URL redirect/cloak with mod_rewrite

Posted by Boyle Owen <Ow...@swx.com>.
________________________________

	From: Hank [mailto:heskin@gmail.com] 
	Sent: Monday, April 21, 2008 1:43 AM
	To: users@httpd.apache.org
	Subject: [users@httpd] silent URL redirect/cloak with
mod_rewrite
	
	
	Hello All,
	 
	I've tried about 100 combinations and searched google over and
over, but I can't find nor figure out how to do this simple task.
	 
	I have one webserver with sites at:
	 
	/home/user/public_html/  ( http://basedomain.com
<http://basedomain.com/>  site points here) 
	/home/user/public_html/siteA
	/home/user/public_html/siteB
	 
	I have domain names like this:  http://domainA.com
<http://domaina.com/>  and http://domainB.com <http://domainb.com/>  
	 
	I want to *silently* redirect http://domainA.com
<http://domaina.com/>  to  /home/user/public_html/siteA 
	and http://domainB.com <http://domainb.com/>  to
/home/user/public_html/siteB
	 
	Now keep in mind the literals "domainA" is not the same as the
directory name "siteA", and same for domainA/siteA.
	 
	I have found several ways to non-silently redirect
http://domainA.com <http://domaina.com/>  to http://basedomain/siteA,
but that's not good enough.  It needs to be a silent re-direct. 
	 
	I realize I could do this with virtual domains if I had access
to httpd.conf, but I don't on this server.
	 
	Thanks,
	-Hank

If I understand you correctly, you have registered domainA and domainB
and the domain names point to your server's IP in DNS. You want to map
domainA to ../siteA and domainB to ../siteB. You don't have access to
the server's httpd.conf directly and only have access to .htaccess
files. 
 
Then I don't think this is possible. Here's why:
 
The NameVirtualHost mechanism is specifically designed for this
situation, but this has to be used in the main config - it is impossible
to do this in .htaccess. The problem is that although the request (for
domainA, say) might come in with a header like "Host: domainA", without
a NameVirtualHost directive and a corresponding VH, this will be ignored
and the request will go the main docroot.
 
BTW, "redirect" has a very specific meaning in HTTP - it means to send a
301 or 302 redirect response that causes the browser to submit a new
request to a new URL. It is always non-"silent" - ie, the browser
location display shows the new URL. By "silent redirect", I think you
mean proxying - where the server gets content from a new URL and returns
it to the browser without telling it where it came from. That's a
different thing and is never referred to as redirection.
Rgds,
Owen Boyle
Disclaimer: Any disclaimer attached to this message may be ignored.
 
 
This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. If you receive this message in error, please notify the sender urgently and then immediately delete the message and any copies of it from your system. Please also immediately destroy any hardcopies of the message. The sender's company reserves the right to monitor all e-mail communications through their networks.

AW: [users@httpd] silent URL redirect/cloak with mod_rewrite

Posted by ch...@post.ch.
Hey Hank,
 
What do you mean by "silent redirect"?
 
Christian

________________________________

Von: Hank [mailto:heskin@gmail.com] 
Gesendet: Montag, 21. April 2008 01:43
An: users@httpd.apache.org
Betreff: [users@httpd] silent URL redirect/cloak with mod_rewrite


Hello All,
 
I've tried about 100 combinations and searched google over and over, but
I can't find nor figure out how to do this simple task.
 
I have one webserver with sites at:
 
/home/user/public_html/  ( http://basedomain.com
<http://basedomain.com/>  site points here) 
/home/user/public_html/siteA
/home/user/public_html/siteB
 
I have domain names like this:  http://domainA.com <http://domaina.com/>
and http://domainB.com <http://domainb.com/>  
 
I want to *silently* redirect http://domainA.com <http://domaina.com/>
to  /home/user/public_html/siteA 
and http://domainB.com <http://domainb.com/>  to
/home/user/public_html/siteB
 
Now keep in mind the literals "domainA" is not the same as the directory
name "siteA", and same for domainA/siteA.
 
I have found several ways to non-silently redirect http://domainA.com
<http://domaina.com/>  to http://basedomain/siteA, but that's not good
enough.  It needs to be a silent re-direct. 
 
I realize I could do this with virtual domains if I had access to
httpd.conf, but I don't on this server.
 
Thanks,
-Hank

Re: [users@httpd] silent URL redirect/cloak with mod_rewrite

Posted by Krist van Besien <kr...@gmail.com>.
On Mon, Apr 21, 2008 at 1:42 AM, Hank <he...@gmail.com> wrote:

> I have found several ways to non-silently redirect http://domainA.com to
> http://basedomain/siteA, but that's not good enough.  It needs to be a
> silent re-direct.

As someone else allready pointed out: There is no such thing as a
"silent" re-direct. What you want is called proxying. The only way I
could imagine doing this would be using rewrite rules.

/home/user/public_html/.htaccess would then have to contain something like this:

RewriteEngine On
RewriteBase /

RewriteCond  $HTTP_HOST   DomainA.com
RewriteRule   ^(.*)$                http://basedomain.com/SiteA/$1   [P]

RewriteCond  $HTTP_HOST   DomainB.com
RewriteRule   ^(.*)$                http://basedomain.com/SiteB/$1   [P]


Krist

-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org