Domain redirection in htaccess not working
-
26-12-2020 - |
Question
I have changed domain on the Magento store, however I need to still keep old domain urls accessible and redirected to new domain urls.
for example. old-domain.com/products should redirect to new-domain.com/products
This is from my current htaccess
Options +FollowSymLinks
RewriteEngine on
# RewriteCond %{HTTP_HOST} ^old-domain\.com$ [OR]
# RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$
# RewriteRule (.*)$ http://www.new-domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
as you can see, I tried 2 versions,
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$
RewriteRule (.*)$ http://www.new-domain.com/$1 [R=301,L]
and
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [R=301,L]
But none of them work. Yes, I have disabled caching in Magento and yes, just in any case, I still flush the cache in Magento and I clear cache in browser too.
I dont know if this matters but anyways. Both new and old domains are controlled by godaddy, with its default nameservers, and both domains have @ record pointed to my server IP address.
Please help : )
Note: of course, I have real domains in the htaccess instead of old-domain.com and new-domain.com
Currently any kind of url with old domain, just redirects to homepage of new domain.
La solution
Let's try this one:
https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules
should be useful. Have you enabled mod_rewrite?
Oh I found reason why it didn't works for You. Please try something like:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.new-domain.com$ [NC]
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]
EDIT:
here are parameters You can use:
- C (chained with next rule)
- CO=cookie (set specified cookie)
- E=var:value (set environment variable var to value)
- F (forbidden - sends a 403 header to the user)
- G (gone - no longer exists)
- H=handler (set handler)
- L (last - stop processing rules)
- N (next - continue processing rules)
- NC (case insensitive)
- NE (do not escape special URL characters in output)
- NS (ignore this rule if the request is a subrequest)
- P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
- PT (pass through - use when processing URLs with additional handlers, e.g., mod_alias)
- R (temporary redirect to new URL)
- R=301 (permanent redirect to new URL)
- QSA (append query string from request to substituted URL)
- S=x (skip next x rules)
- T=mime-type (force specified mime type)