Welcome to WebmasterWorld Guest from 54.167.58.159

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

how to do a rewrite of a hostname

     

jxexbxuxs

12:35 am on Jun 19, 2010 (gmt 0)

5+ Year Member



I'm sure this is a very simple process but I can't seem to get it to work.

I have a host that can be accessed from myhost.ops and from myhost.ops.expert.com. I have an ssl cert that only works for myhost.ops.expert.com so if someone tries to access the http server from myhost.ops they are successful but ssl doesn't work.
So I want to rewrite myhost.ops to be myhost.ops.expert.com and I have had no luck with this. Any help would be appreciated?

thanks

g1smd

7:45 am on Jun 19, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You'll need a redirect. There's close on 30 000 examples of similar code in this forum.

Use a RewriteCond to check which host is requested, and if it is not the correct one, the following RewriteRule will redirect the user to the correct URL. If you want to retain the requested path, capture it in a (.*) pattern and reuse it as $1 in the target. Use the [R=301,L] flags to finish the job.

Let's see your code.

jxexbxuxs

6:05 pm on Jun 21, 2010 (gmt 0)

5+ Year Member



thanks for the response. I did search in the forums, but I guess I just wasn't looking for the right keywords.

here is the code:
RewriteCond %{HTTP_HOST} ^myhost\.ops\.expert\.com [NC]
#RewriteCond %{HTTP_HOST} ^myhost\.ops [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) [myhost.ops.expert...] [L,R=301,L]


The commented out line is another RewriteCond that i tried with no luck.

jdMorgan

6:32 pm on Jun 21, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The "check for blank" RewriteCond is redundant in this case, since a match on the previous RewriteCond indicates that the hostname was not blank. The blank-check is primarily useful when a negative-match on a hostname is being used.

In addition, using the "exact-string match" operator when possible is faster, instead of using the regex library.

So the code reduces to:

RewriteCond %{HTTP_HOST} ^myhost\.ops\.expert\.com [NC]
RewriteCond %{SERVER_PORT} !=80
RewriteRule ^/(.*)$ https://myhost.ops.expert/$1 [L,R=301,L]

If the goal here is to only redirect HTTPS requests, then consider using the pattern "=443" instead of using the pattern "!=80".

Jim

jxexbxuxs

6:45 pm on Jun 21, 2010 (gmt 0)

5+ Year Member



this is what i changed it do (it didn't work):

RewriteCond %{HTTP_HOST} ^myhost\.ops\.expert\.com [NC]
RewriteCond %{SERVER_PORT} =4443
RewriteRule ^/(.*) [myhost.ops.expert.com...] [L,R=301,L]


it is listening on port 4443

what i am trying to accomplish is the following; I want to rewrite:
[myhost.ops:4443...]
as
[myhost.ops.expert.com:4443...]

jdMorgan

7:30 pm on Jun 21, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Check your usage of terms.

Do you want to externally redirect a client from one URL to another URL, or do you want to internally rewrite a request for a URL to a non-default server filepath?

Which is the "wrong" hostname, and which is the "right" hostname?

Which host is this code installed on? Or are they actually the same host?

Is this code located within a <Directory /apex/apex/> container?

Jim

jxexbxuxs

9:33 pm on Jun 21, 2010 (gmt 0)

5+ Year Member



I'm an oracle dba and I am just using Apache to service an oracle web client(apex) so my understanding of this is very limited.

The problem is that the ssl certification is only valid for myhost.ops.expert.com,
but a user can access the webapp at myhost.ops and if they do they get an invalid certificate.

What I have been able to accomplish is if a user types in [myhost.ops.expert.com:7777...] then it gets rewriten(redirected?) as [myhost.ops.expert.com:4443...] and is able to use the valid certificate. I want this to happen if the user types in [myhost.ops:4443...]

the code I am using to rewrite(redirect?) the http address to https address is:
RewriteCond %{SERVER_PORT} !^4443$
RewriteRule ^/apex/(.*)$ [myhost.ops.expert.com:4443...] [L,R]

g1smd

9:51 pm on Jun 21, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You'll probably want to change the R to R=301 here.

jxexbxuxs

10:57 pm on Jun 21, 2010 (gmt 0)

5+ Year Member



I tried just this:

RewriteRule ^/apex/(.*)$ [myhost.ops.expert.com:4443...] [L,R=301]

it still worked to rewrite the http address to [myhost.ops.expert.cop:4443,...]
but I can't get it to rewrite [myhost.ops:4443...] to [myhost.ops.expert.cop:4443....]

Is there something that I am missing when trying to rewrite an https address to an https address?

jdMorgan

11:54 pm on Jun 21, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



That's apparently because the pattern in the left side of your rule contains "/apex/" and the URL you're having trouble redirecting does not contain "/apex/"

The pattern has to match the requested URL-path, or the rule won't be invoked.

Jim

jxexbxuxs

12:37 am on Jun 22, 2010 (gmt 0)

5+ Year Member



sorry for the confusion, I just didn't write out the complete url:

I can't get it to rewrite [myhost.ops:4443...] to [myhost.ops.expert.com:4443...]

Is there something that I am missing when trying to rewrite an https address to an https address?

jdMorgan

3:27 pm on Jun 22, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



There's nothing particularly tricky about it except that http vs. https must be detected indirectly using the %{HTTPS} or %{SERVER_PORT} variable as already done.

However, the patterns have to match the desired requested URL-paths, and the code has to be located where it will be executed when those URL-paths are requested -- e.g. in the proper VirtualHost, <Directory> container, or .htaccess file (as applicable).

Because your URL-path patterns start with a slash, that implies that this code is located in a server config file and is not contained within any <Diretory> container in that config file.

In addition, beware of other modules which can be invoked before mod_rewrite and pre-empt it. Examples include mod_alias, mod_proxy, mod_dir, mod_negotiation, mod_speling, and possibly, additional third party modules.

Jim