How to do lots of 301 Redirect (Tomcat?

How to do lots of 301 Redirect (Tomcat) with complete urls

  • I have several websites running on a single tomcat instance, and at application level the cms reads the domain and it is smart enough to show the right website to the user. For example I have www.firstwebsite.com/welcome and the cms shows the homepage for firstwebsite, while when it receives requests with the domain www.secondwebsite.com/welcome the cms shows the welcome page for secondwebsite. But both websites has just replaced two old website with different url structure, for example the old www.firstwebsite.com/my-product-in-old-website should redirect (301) to the page www.firstwebsite.com/my-product-in-new-website. The same happens for secondwebsite. Please note that the redirect is not based by path, but it is also based on the domain name, i.e. if I define a redirect for /my-product-in-old-website the redirect is sent for both websites instead of only for firstwebsite. Is there anything that allows me to do 301 redirect based on the full url of the request (website domain included)? EDIT New and old urls does not follow a particular pattern so for example firstwebsite.com/something/something/my-old-page -> firstwebsite.com/something-else/my-new-page firstwebsite.com/my-old-page2 -> firstwebsite.com/something/something/my-new-page2 and secondwebsite.com/somethingelse/somethingelse/my-old-page -> secondwebsite.com/somethingelse-xyz/my-new-page secondwebsite.com/my-old-pageXYZ -> secondwebsite.com/something/something/my-new-page-ABC

  • Answer:

    You can use RewriteCond which tests domain and next RwriteRule will run only when RewriteCond condition true. So, you can write rules for different domain separately. But in your case you should write rule for every path, unfortunatly. But, if there are the same redirects, you can write its once Make some rules Common: RewriteRule ^my-old-page$ /my-new-page [R,L] Diff: RewriteCond %{HTTP_HOST} ^firstwebsite.com$ RewriteRule ^my-old-page2$ /my-new-page2 [R,L] and so on... If you not planning more changing url in .htaccess, you can write [END] instead [L]

daniele at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.