I've read everything I could and can't figure this out. I need a simple page redirect that keeps the original subdomain. We have several stores on their own subdomains with identical product page names, so if someone visits URLs like these:
https://XYZ.example.com/old-product.html
https://ABC.example.com/old-product.html
We need to redirect them to the new product page like so:
https://XYZ.example.com/new-product-page.html
https://ABC.example.com/new-product-page.html
I tried something simple like this, but it redirects to our main www site instead of keeping the subdomain.
RewriteRule ^old-product.html$ new-product-page.html [NC]
I don't know how to catch the subdomain and use it for the rewrite. Can anyone help me? Thanks so much.
EDIT:
Here's my .htaccess file
, it's a Magento 1.9 site:
# Force www
RewriteCond %{HTTP_HOST} ^example.com
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
SetEnvIf SERVER_PORT 443 HTTPS=on
# Force https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
# XYZ Env Variables
SetEnvIf Host www\.XYZ\.example\.com MAGE_RUN_CODE=XYZ_website
SetEnvIf Host www\.XYZ\.example\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^XYZ\.example\.com MAGE_RUN_CODE=XYZ_website
SetEnvIf Host ^XYZ\.example\.com MAGE_RUN_TYPE=website
# ABC Env Variables
SetEnvIf Host www\.ABC\.example\.com MAGE_RUN_CODE=abc_website
SetEnvIf Host www\.ABC\.example\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^ABC\.example\.com MAGE_RUN_CODE=abc_website
SetEnvIf Host ^ABC\.example\.com MAGE_RUN_TYPE=website
<IfModule mod_ssl.c>
############################################
## make HTTPS env vars available for CGI mode
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
</IfModule>
EDIT 2: Well I figured out part of the answer:
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC]
RewriteRule ^(.*)old-product.html$ new-product-page.html [R=301,L]
That's returning a URL like this:
https://www.example.com/live/public_html/new-product-page.html
How can I remove the /live/public_html
part?