Issue
- How can I redirect traffic from my non-www domain (e.g.,
example.com
) to my www domain (e.g.,www.example.com
)?
Environment
- Liferay DXP 7.4
- Quarterly Releases
Resolution
You can configure a redirect using Liferay's pattern redirect feature:
- Access your website and navigate to Configuration > Site Settings > Site Configuration > Site URLs. Remove the non-www domain, keeping only the www domain. (e.g.,
www.example.com
) - reate a new site specifically for handling the redirect. In the Site URLs configuration for this new site, add the non-www domain. (e.g.,
example.com
) - In the new site, navigate to Configuration > Redirection > Patterns and add the following configuration:
-
Pattern:
^(.*)
-
Target URL:
https://www.example.com/$0
(Replaceexample.com
with your actual domain) - User Agent: all
-
Pattern:
This configuration redirects all traffic from the non-www domain to the corresponding URL on the www domain. For example, example.com/page
will redirect to www.example.com/page
.
Additional Information
- This method uses 302 redirects, which can negatively impact SEO. For optimal SEO, configure 301 redirects at your web server level if possible.
- See Using Pattern Redirects for more details.