Yandiro
Yandiro

Reputation: 157

.htaccess redirect wildcard - moving subdomain to different domain

subdomain is unchanged: loja

Old domain: loja.churrascoelareira.com.br

new domain loja.bomdebrasa.com

The thing is that google is still sending visitors to urls like this: loja.churrascoelareira.com.br/exemple-product-page.html

How can I forward that to: loja.bomdebrasa.com/exemple-product-page.html

with wildcards?

EDIT1: The file is like the following (both domains point to the same server) and this file is located in tow folders (just to make sure): public_html and public_html/churrascoelareira.com.br

Bellow this code there is an image of the cPanel's parked domain.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ $1.php [L]

# Google Analytics Integration - Added by cPanel.
<IfModule mod_substitute.c>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|(<script src='/google_analytics_auto.js'></script>)?</head>|<script src='/google_analytics_auto.js'></script></head>|i"
</IfModule>
# END Google Analytics Integration
RewriteCond %{HTTP_HOST} ^bomdebrasa\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.bomdebrasa\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/www\.bomdebrasa\.com\/newsite\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^bomdebrasa\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.bomdebrasa\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^site\/?$ "http\:\/\/bomdebrasa\.com\/newsite" [R=301,L]
RewriteCond %{HTTP_HOST} ^bomdebrasa\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.bomdebrasa\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^site\/produtos$ "http\:\/\/bomdebrasa\.com\/newsite" [R=301,L]
RewriteCond %{HTTP_HOST} ^loja\.churrascoelareira\.com\.br$
RewriteRule ^/?(.*)$ https://loja.bomdebrasa.com/$1 [R=301,QSA]

# php -- BEGIN cPanel-generated handler, do not edit
# NOTE this account's php is controlled via FPM and the vhost, this is a place holder.
# Do not edit. This next line is to support the cPanel php wrapper (php_cli).
# AddType application/x-httpd-ea-php56 .php .phtml
# php -- END cPanel-generated handler, do not edit

cPAnel's parked domain: enter image description here

EDIT2: I finally found where (in this outdated cPanel version) to do the redirects with wildcards. So this is solved (not by manually creating the file, but solved) and I checked the .htaccess file that was already there and saw nothing new, so I guess it was done in another way.

Upvotes: 0

Views: 445

Answers (1)

arkascha
arkascha

Reputation: 42974

Not sure what you mean by "wildcard" here, but this rule setup should forward those requests to the new domain, if it is implmented in the old http host:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^loja\.churrascoelareira\.com\.br$
RewriteRule ^/?(.*)$ https://loja.bomdebrasa.com/$1 [R=301,QSA]

For this to work you obviously need to have the rewriting module enabled and loaded in the old http host. The rule set will work likewise in the http server's host configuration or inside a dynamic configuration file (".htaccess"), you should however prefer the first option. If you decide to use a dynamic configuration file then take care that it's interpretation is enabled for the old http host and that the file is located in the host's DOCUMENT_ROOT folder and readable by the http server process.

Upvotes: 2

Related Questions