_hirro Posted August 3, 2007 Share Posted August 3, 2007 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. Quote Link to comment Share on other sites More sharing options...
steviewdr Posted August 4, 2007 Share Posted August 4, 2007 Put the following in a htaccess file in the root folder of www.thisismysite.com and thisismysite.com Redirect 301 /resource1 http://www.mysite.com/resource1 -steve Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 4, 2007 Share Posted August 4, 2007 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 Quote Link to comment Share on other sites More sharing options...
steviewdr Posted August 6, 2007 Share Posted August 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
_hirro Posted August 10, 2007 Author Share Posted August 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
steviewdr Posted August 13, 2007 Share Posted August 13, 2007 <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 Quote Link to comment Share on other sites More sharing options...
_hirro Posted August 20, 2007 Author Share Posted August 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
_hirro Posted August 20, 2007 Author Share Posted August 20, 2007 I'm thinking something like this may be the solution: http://borkweb.com/story/apache-rewrite-cheatsheet In addition to our JBOSS CDA cluster needing the correct URL, I just realized our analytics package filters based on that URL as well. I need to make sure all requests make it to www.mysite.com. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.