Need 301 help to understand and maybe fix

I am trying to help a friend with moving from her old static site to a new wordpress site. She has a new domain and a new server. I think the names involved are making this harder than normal, but maybe not.

She is going from hersite.com to her-site.com

The old site has a little over 4,000 pages.

Someone at her hosting company set up the following redirect on her htaccess on the old server:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.hersite.com$ [OR]
RewriteCond %{HTTP_HOST} ^hersite.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.her\\-site\\.com\\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^www.hersite.com$ [OR]
RewriteCond %{HTTP_HOST} ^hersite.com$
RewriteRule ^\\*$ "http\\:\\/\\/www\\.her\\-site\\.com\\/" [R=301,L]

I am not good enough with redirects or htaccess to really understand what is going on with that code. I definitely don’t know what is up with all of the ^ or the \/ stuff.

Is that a good redirect code? Is there a better way to handle this kind of redirect?

Hi pauloyler . Welcome to the forums. :slight_smile:

This is off topic, but why is she not using the same domain name for the new site? Moving to a different domain will completely wipe all the seo value the site has accrued. And to have a redirect on the old hosting account (as far as I know) requires that the old hosting account be kept alive, which doubles the hosting cost.

The first few lines looks like it will match the root path of the old site and redirect to the root path of the new site. One URL down; 3,999 more to go. The second block looks like the author meant to match all other URLs, but actually just matched a literal “*” instead.

Probably you want something like this:

[FONT=Courier New]RewriteEngine On

# If this request came from the old host ("www" is optional)
RewriteCond %{HTTP_HOST} ^(?:www\\.)?hersite\\.com$ [NC]

# then redirect all URLs to the same URL on the new host
RewriteRule ^(.*)$ http://www.her-site.com/$1 [R=301,L][/FONT]

Thank you for the welcome Ralph!

I know what you mean, and I totally get that and I think she does now too, but now both sites are live and getting decent amounts of traffic and she doesn’t know what to do so she just wants to continue as is for now with the hope that in six months she can eliminate the old site completely.

Thank you Jeff. I have copied your solution and I’ll give it a try and we’ll see what happens.

The same friend that I asked help for earlier has 4 domain names that she has had parked on her old domain and now has parked on her new domain.

I think I read that it is better to do a 301 redirect instead of parking a domain, but then today I read something that seemed to imply we should do both. She asked her hosting company and the said they have it taken care of, but whatever they did does not seem to be working. I checked their htaccess file again and this is what they have:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^parkedsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^parkedsite-2.com$ [OR]
RewriteCond %{HTTP_HOST} ^parkedsite-3.com$ [OR]
RewriteCond %{HTTP_HOST} ^parkedsite-4.com$
RewriteRule ^(.*)$ http://www.mainsite.com/$1 [R=301]

Since that definitely does not seem to be working, can anyone tell me what should be there?

Thanks,
Paul

Paul,

There is no reason that the code you gave will not work IF the parkedsites are, indeed, parked on maindomain (despite two MINOR comments on their code) AND www’d domain names are not being used. Since you’d stated that they are parked, then your testing must be to www.parkedsite.com so, no, that will not work. That said, simply removing the start anchors will remove that obstacle.

RewriteEngine on
RewriteCond %{HTTP_HOST} [COLOR="#FF0000"]^[/COLOR]parkedsite[size=6]\\[/size].com$ [OR]
RewriteCond %{HTTP_HOST} [COLOR="#FF0000"]^[/COLOR]parkedsite-2[size=6]\\[/size].com$ [OR]
RewriteCond %{HTTP_HOST} [COLOR="#FF0000"]^[/COLOR]parkedsite-3[size=6]\\[/size].com$ [OR]
RewriteCond %{HTTP_HOST} [COLOR="#FF0000"]^[/COLOR]parkedsite-4[size=6]\\[/size].com$

# Your host should know to escape the dot characters in regex to ensure they only match the dot character.
# - NOT within a character range definition, though.

RewriteRule ^(.*)$ http://www.mainsite.com/$1 [R=301[COLOR="#0000FF"],L[/COLOR]]

# No other code in the .htaccess? Oh, well, IMHO the use of the Last flag helps mod_rewrite.
# If nothing else, it keeps my mind clear that this code is one RewriteRule block.
#
# Also, I prefer not to duplicate the {$REQUEST_URI} variable so I would have used
# RewriteRule .? http://www.mainsite.com%{REQUEST_URI} [R=301,L]
#   but that's just a "professional thing" with me and makes no difference here.

Regards,

DK

Thank you David! I don’t completely understand all that you said, but I’m trying to learn… (reading this forum and trying to learn from context)

I have now been given access to the cpanel for the site, and what was listed within cpanel did not look right at all, as far a where the parked domains were being redirected to. So I deleted all of the parked domains and then re-entered them. That seems to have changed the htaccess file, and with permission I am sharing it as it actually is:

#------------
#Parked Domains, added by cPanel
#---------
RewriteCond %{HTTP_HOST} ^pavendor\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.pavendor\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^pennsylvaniavendors\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.pennsylvaniavendors\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^vendorsinpa\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.vendorsinpa\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^pavendorevents\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.pavendorevents\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

Is that the way it should be?
It doesn’t seem to be working, because I’m still getting

Firefox can’t find the server at www.pavendorevents.com.

We’re still having some trouble with this migration, and I’m sure some (alot?..most?) of it is due to moving from static html to WordPress.

I received this from my friend this afternoon:

I searched “Flea Markets Richboro PA” and we are listed #1 (after the scrolling pictorial that Google has done.) The link doesn’t work and we’re not getting a re-direct page.
The URL is correct with the exception of a .htm on the end! If it wasn’t for the .htm, the link would work.
The link should be: http://pa-vendors.com/events/bucks-county/richboro-pa-lions-vendor-fair-and-flea-market/

So, is there anything we can do or add to the redirect that would strip the “htm” or “.html” from the redirect to take a visitor to the correct page?

With permission, I am sharing the entire htaccess so anyone can see what is already in place.
(And if anyone sees ANYTHING that might not be right, even if not directly related to this, please let me know. I’m not very well-versed in htaccess files, but I’m trying to learn)

<IfModule mod_suphp.c>
suPHP_ConfigPath /home/paven1/public_html/
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
RewriteEngine On

# Dynamically add www:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/robots\\.txt$ [NC]
RewriteCond %{HTTP_HOST} !^www\\.[a-z-]+\\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\\.[a-z]{2,6})$ [NC]

#Added for extra security to prevent the viewing of .htaccess and your php.ini (added by Lunarpages MSH Team):

<Files .htaccess>
order allow,deny
deny from all
</Files>

<Files php.ini>
order allow,deny
deny from all
</Files>

#The following batch of code can help prevent XSS attacks (added by Lunarpages MSH Team):

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode.*\\(.*\\) [OR]
RewriteCond %{QUERY_STRING} (\\<|%3C).*script.*(\\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\\<|%3C).*iframe.*(\\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\\[|\\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\\[|\\%[0-9A-Z]{0,2})
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)

#-------------------------------
#Sql injection blockage, added by Lunarpages MSH Team
#----------------------------------------
RewriteCond %{REQUEST_METHOD} (GET|POST) [NC]
RewriteCond %{QUERY_STRING} ^(.*)(%20(S|%73|%53)(E|%65|%45)(L|%6C|%4C)(E|%65|%45)(C|%63|%43)(T|%74|%54)%20|%20(I|%69|%49)(N|%6E|%4E)(S|%73|%53)(E|%65|%45)(R|%72|%52)(T|%74|%54)%20|(C|%63|%43)(H|%68|%48)(A|%61|%41)(R|%72|%52)\\(|%20(U|%75|%55)(P|%70|%50)(D|%64|%44)(A|%61|%41)(T|%74|%54)(E|%65|%45)%20|%20(R|%72|%52)(E|%65|%45)(P|%70|%50)(L|%6C|%4C)(A|%61|%41)(C|%63|%43)(E|%65|%45)%20)(.*)$ [NC]
RewriteRule (.*) index.php   [F]

#------------
#Parked Domains, added by cPanel
#---------
RewriteCond %{HTTP_HOST} ^pavendor\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.pavendor\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^pennsylvaniavendors\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.pennsylvaniavendors\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^vendorsinpa\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.vendorsinpa\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^pavendorevents\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.pavendorevents\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]


It actually just hit me that I put the htaccess from the site in my last post instead of the file on the old site. (I think I am going batty from trying to figure this stuff out!)

Here is the file, as it is on the old site, which needs to redirect to the new site - and hopefully - strip out the “.htm”

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.pavendors.com$ [OR]
RewriteCond %{HTTP_HOST} ^pavendors.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

# If this request came from the old host ("www" is optional)
RewriteCond %{HTTP_HOST} ^(?:www\\.)?pavendors\\.com$ [NC]

# then redirect all URLs to the same URL on the new host
RewriteRule ^(.*)$ http://www.pa-vendors.com/$1 [R=301,L]
Off Topic:

I’m no good with this stuff, but perhaps @dklynn can help with this.

So, if I understand correctly, you want to redirect oldsite.com/some/page.htm to newsite.com/some/page/. Is that right? If so, then this is probably what you need.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.pavendors.com$ [OR]
RewriteCond %{HTTP_HOST} ^pavendors.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.pa\\-vendors\\.com\\/" [R=301,L]

[COLOR="#FF0000"]# If this request came from the old host ("www" is optional)
# then redirect all .htm URLs to extensionless URL on the new host
RewriteCond %{HTTP_HOST} ^(?:www\\.)?pavendors\\.com$ [NC]
RewriteRule ^(.*)\\.htm$ http://www.pa-vendors.com/$1/ [R=301,L][/COLOR]

# Redirect all other URLs to the same URL on the new host
RewriteCond %{HTTP_HOST} ^(?:www\\.)?pavendors\\.com$ [NC]
RewriteRule ^(.*)$ http://www.pa-vendors.com/$1 [R=301,L]

I was hoping that maybe after 24 hours or so, the parked redirects would take effect, but still getting the same error that Firefox can’t find the server.

Is there anything else we could try to have these parked domains point to pa-vendors[DOT]com?

Thanks Jeff. I just tried putting that code in and it still is taking a person to the “.htm” page, which produces a 404.
pavendors[DOT]com/event-services/paparazzi-jewelry-and-accessories.htm is redirecting to pa-vendors[DOT]com/event-services/paparazzi-jewelry-and-accessories.htm

Edited to add that apparently one of her employees was just redirected to the correct page, so maybe it is just taking time to work?

You forgot to remove the "starts with"s - the ^ - that Paul highlighted red in his example so your’s is more complex then need be.
And your RewriteRule is escaped.

Paul,

cPanel did a lousy job of creating mod_rewrite code, however, you have only two small problems that I can see (other than a lot of @#$% in your .htaccess file).

First, the code you gave in post #5 was fine EXCEPT that it required the non-www’d versions of your parked websites. Remove the start anchor (‘^’) from the RewriteCond statements to correct those.

Second, I prefer to use site-wide mod_rewrite (changing domain names and forcing www’s) before getting into specifics (WP’s code). Simply put your code in front of the WP code (only one RewriteEngine on, please).

I’ll leave it to others to critique the rest of the .htaccess as, at this late hour, I’d probably get hopelessly pedantic.

Regards,

DK