I wish to 301 redirect all the internal pages of old URL to a singal destination of new URL via htaccess file.
like I am looking to redirect http://www.advancedbuildings.org/main_t_lighting_e_dimmable_ballasts.htm
and all other internal pages to https://teamemergencyplumber.com/advancedbuildings-org/
.
I am using this code right now
RewriteEngine On
# Redirect main domain
RewriteCond %{HTTP_HOST} ^(www\.)?advancedbuildings\.org$ [NC]
RewriteRule ^$ https://teamemergencyplumber.com/advancedbuildings-org/ [L,R=301,NE]
# Redirect internal pages
RewriteCond %{HTTP_HOST} ^(www\.)?advancedbuildings\.org$ [NC]
RewriteRule ^(.*)$ https://teamemergencyplumber.com/advancedbuildings-org/$1 [L,R=301,NE,QSD]
its coming up with an error like https://teamemergencyplumber.com/advancedbuildings-org/main_t_lighting_e_dimmable_ballasts.htm
. its adding string from source URl to destination URl which is causing a 404 error. For home page its working fine .
Can you suggest a code to fix that error ?
# Redirect main domain RewriteCond %{HTTP_HOST} ^(www\.)?advancedbuildings\.org$ [NC] RewriteRule ^$ https://teamemergencyplumber.com/advancedbuildings-org/ [L,R=301,NE] -----HERE----^
Just remove the $
(end-of-string anchor) on the RewriteRule
pattern (so that it does not only match the homepage) and delete the second rule altogether. In other words:
# Redirect main domain and all internal pages
RewriteCond %{HTTP_HOST} ^(www\.)?advancedbuildings\.org$ [NC]
RewriteRule ^ https://teamemergencyplumber.com/advancedbuildings-org/ [L,R=301]
(The NE
flag is not necessary here.)
This now redirects everything from the first domain to the second domain/URL.
You should test first with a 302 (temporary) redirect to avoid potential caching issues. However, you will need to clear the browser (and all intermediary) cache(s) since the erroneous 301 (permanent) redirect you had previously implemented will have been cached!
Note, however, that a many-to-one redirect like this is likely to be seen as a soft-404 by search engines.