如何在WebLogic设置中将localhost:7001重定向至localhost:7001/myApp(非web.xml)?
Absolutely doable! You don’t need to mess with your application’s web.xml at all—WebLogic provides server-level configurations to handle this exact redirect. Here are two solid methods you can implement:
This method maps the root URL (localhost:7001) directly to your app by setting it as the default web application for a virtual host:
- Open the WebLogic Administration Console and log in with your admin credentials.
- Navigate to Environment > Virtual Hosts and click New to create a new virtual host.
- Give it a descriptive name (e.g.,
RootRedirectHost) and set the Network Access Point Name to your server’s listen address (usuallyDefault). - Switch to the Host Names tab and add
localhostas the host name for this virtual host. - Next, go to Deployments > [Your myApp Deployment] and select the Targets tab.
- Add the newly created virtual host as a target for
myApp(ensure your app’s context root is already set to/myApp—this is the default if you deployed it with that context). - Head to Environment > Servers > [Your Server Name] > HTTP tab.
- Scroll down to the Default Web App section and select
myAppfrom the dropdown menu. - Save all changes and restart your WebLogic server. Now accessing
localhost:7001will automatically route tolocalhost:7001/myApp.
If you prefer a direct redirect (with an HTTP 301/302 response), use WebLogic’s built-in URL rewriting feature:
- In the Administration Console, go to Environment > Servers > [Your Server Name] > Web Applications tab.
- Click Configure URL Rewriting and enable the feature if it’s not already turned on.
- Add a new rewrite rule with these settings:
- Pattern:
^/$(matches the exact root URL request) - Rewrite To:
/myApp - Redirect Type: Choose
302 Temporary Redirector301 Permanent Redirectbased on your needs.
- Pattern:
- Save the rule and restart the server. Any request to
localhost:7001will now be redirected to your app’s context path.
A quick note: Always test these changes in a staging environment first, and ensure you have administrative privileges to modify WebLogic’s server settings. Both methods keep your application’s web.xml completely untouched.
内容的提问来源于stack exchange,提问作者Nurullah Obuz

