: How do I use a htaccess redirect to force www and use the .org domain while maintaining the URL path? I have found this rule that does about 90% of what I want, but not quite everything.
I have found this rule that does about 90% of what I want, but not quite everything. My main goals for the redirect are to 1) force 2) redirect .com to .org. This does that, but if I were at domain.com/page, it just redirects to the home page and not domain.org/page. How can I get it to do this last step as well?
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.org$ [NC]
RewriteRule ^(.*)$ www.domain.org/ [L,R=301]
More posts by @Rivera981
2 Comments
Sorted by latest first Latest Oldest Best
You will want to use your .htaccess file in the root of each site. You will be creating 2 .htaccess files, one per-site. I am assuming that you have each site defined within Apache as two separate sites. This is important to do.
In your .com site:
RewriteEngine on
RewriteRule ^(.*)$ www.domain.org/ [L,R=301]
In your .org site:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.org$ [NC]
RewriteRule ^(.*)$ www.domain.org/ [L,R=301]
This will do two things:
Do a blanket redirect from your .com site to your .org site.
Redirect any non-www request to www preserving the original request.
That should be:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.org$ [NC]
RewriteRule ^(.*)$ www.domain.org/ [L,R=301]
The "" tells mod_rewrite to add the matched text from inside the parentheses in the pattern to the rewritten URL, which is what you want.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.