Jump to content

Directory redirect


_hirro

Recommended Posts

Having trouble with a redirect I haven't had to handle before. My site is setup as www.mysite.com. The site will only respond to requests coming into the application formed that way.

 

I have redirects setup so that mysite.com, thisismysite.com and www.thisismysite.com are all redirected to www.mysite.com. These redirects along with a bunch of other redirects are part of a virtual host all setup on one IP. The real host is setup on a different IP. Unfortunately, someone in marketing decided to publish something in print that has www.thisismysite.com/resource1 as the link for a resource.

 

Redirect:

<VirtualHost 192.168.1.100>

  ServerName www.thisismysite.com

  ServerAlias thisismysite.com mysite.com

  RedirectMatch ^/$ http://www.mysite.com

<VirtualHost 192.168.1.100>

 

Site:

<VirtualHost 192.168.1.101>

  DocumentRoot /usr/local/www/192.168.1.101/docs

  Servername files.mysite.com

  Include conf/hosts/192.168.1.101.common

</VirtualHost>

 

How do I redirect all requests that come into www.thisismysite.com/resource1 and thisismysite.com/resource1 to go to www.mysite.com/resource1 instead?

 

I really appreciate the help.

 

 

Link to comment
Share on other sites

Maybe I'm missing something, but isn't the root folder of www.thisismysite.com and thisismysite.com the same folder, and also the same folder as that for mysite.com? It appears this is a single site with Aliases, not 3 separate sites.

 

If so, I would expect

 

Redirect 301 /resource1 http://www.mysite.com/resource1

 

in the shared directory to cause an error as it will never resolve.

 

Assuming they all do share a common directory, I might use something like this:

 

RewriteCond %{HTTP_HOST} ^thisismysite\.com$ [NC]

RewriteRule ^resource1$ http://www.mysite.com/resource1 [R=301,L]

 

RewriteCond %{HTTP_HOST} ^www\.thisismysite\.com$ [NC]

RewriteRule ^resource1$ http://www.mysite.com/resource1 [R=301,L]

 

Please let me know if this is wrong!

 

-BSIS

 

Link to comment
Share on other sites

Aye - that redirect suggestion I gave will not work.

 

Without me going away and testing it, does:

RedirectMatch ^/$ http://www.mysite.com

 

not redirect all of www.thisismysite.com/blah to www.mysite.com/blah ?

And therefore will www.thisismysite.com/resource1 not be automatically redirected to http://www.mysite.com/resource1

 

You could also try this instead:

 

<VirtualHost 192.168.1.100>

  ServerName www.thisismysite.com

  ServerAlias thisismysite.com mysite.com

  Redirect 301 / http://www.mysite.com/

</VirtualHost 192.168.1.100>

 

That will forward any url, e.g. somesite.com/blah/blah to www.site.com/blah/blah

 

-steve

Link to comment
Share on other sites

The apache server actually hands off the site request to a JBOSS server to dynamically generate the site. The JBOSS server needs to get the request in the www.mysite.com format all other formats (mysite.com, www.thisismysite.com) will throw a error if not redirected to the actual site name.

 

The example given below should work so that at least the request will be redirected to www.mysite.com and not fail.

<VirtualHost 192.168.1.100>

  ServerName www.thisismysite.com

  ServerAlias thisismysite.com mysite.com

  Redirect 301 / http://www.mysite.com/

</VirtualHost 192.168.1.100>

 

But what I really need to know is whenever a request comes in for anything aside from www.mysite.com (i.e. mysite.com or thisismysite.com) replace those site names with www.mysite.com.

 

For example

www.thisismysite.com/directory/34a

goes to

www.mysite.com/directory/34a

 

or

mysite.com/fake/listing/post

is redirected to

www.mysite.com/fake/listing/post

 

As there are 1000s of resoures on our site it isn't possible for me to setup a redirect for each resource. I really appreciate the help, this board has been quite helpful.

Link to comment
Share on other sites

<VirtualHost 192.168.1.100>

  ServerName www.thisismysite.com

  ServerAlias thisismysite.com mysite.com

  Redirect 301 / http://www.mysite.com/

</VirtualHost 192.168.1.100>

 

<VirtualHost 192.168.1.100>

  ServerName www.mysite.com

  DocumentRoot /var/www/

</VirtualHost 192.168.1.100>

 

This will do as you want. EOF.

 

-steve

Link to comment
Share on other sites

I gave that a shot unfortunetly it doesn't work in my setup. We are using mod_jk to hand off requests to our JBOSS CDA cluster.

 

This is why I need the request to be rewritten.

It must be passed off to the jboss server with www.mysite.com/whatever as the request.

 

So if we accidently advertise something as mysite.com/whatever and people go to that site we need the request rewritten to www.mysite.com/whatever when it comes in. That way the JBOSS CDA knows what content to deliver.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.