Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

All 301 redirects in WP .htaccess work but this stubborn one

create 301 redirects in .htaccess

         

jastra

6:51 pm on Jan 12, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



I've converted a old classic ASP site to a WP theme and it's up and running OK. And when I used the WP .htaccess file to 301 redirect all those old ASP pages to the current WP equivalents all went well except one line.

I had a Blogspot blog from many years ago in a subdomain. The new WP posts are in a folder of the WP theme. Here's the line in the .htaccess file that won't properly redirect:

Redirect 301 http://hotelblog.example.com/ http://www.example.com/blog/

What am I doing wrong? I tried removing the http:// from the old URL but it had no effect.

not2easy

8:26 pm on Jan 12, 2016 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Because you are using an .htaccess file I assume you have moved to an Apache server. Is that correct?
If so:
1. Where is the htaccess file you are using to redirect the /oldblog/ URLs in relation to the new WP installation? Is it separate from the root directory?
2. Are all your rewrites in this "Redirect Match" (mod_alias) type format? Is the WordPress generated 301 Rewrite (using mod_rewrite) in a separate directory? I ask because in the case of mixing the two types of rewrites in the same htaccess file, you can have surprising results. They do not necessarily follow the order shown in your htaccess file and all of one type will execute before the other. Exact order depends on how the server settings are configured. It is best to avoid mixing the two types of Rewrites.

jastra

8:46 pm on Jan 12, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks for the reply. Yes, I moved the content from Windows hosting to Apache. Godaddy Managed Wordpress hosting, and this server setup is new to me.
1. The .htaccess file is however at the same directory level as wp-admin, wp-includes, wp-content etc.
2. Yes, the redirects are in the same .htaccess file as mod_rewrites.

I followed the advice found on a how-to page after a google search. All redirects are at the top of the .htaccess file like this:

#User added 301 Redirects
All 10 redirects here
#End User added 301 Redirects

And then the default WP .htaccess file followed.

So you're advising I create another .htaccess file solely for the redirects? What would I name it? I'm clearly learning as I go here.

ergophobe

9:05 pm on Jan 12, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



not2easy is recommending that you use mod_rewrite (RewriteRule, etc) for everything in that file since you already have the WP mod_rewrite rules in there.

If you have mod_rewrite rules and mod_alias rules in the same file, things can get crazy. Like perhaps mod_rewrite is rewriting the URL before mod_alias kicks in, in which case the mod_alias redirect will not match.

jastra

9:17 pm on Jan 12, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



OK thanks not2easy and ergophobe. Now I understand what you mean. I have some studying to do on mod_rewrite rules.

lucy24

9:28 pm on Jan 12, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Like perhaps

I don't think there's any "perhaps" about it :( Someone hereabouts delved into Apache docs and finally found something that says mod_rewrite always executes before mod_alias. (The rough-and-ready rule is: mods run in reverse alphabetical order. This may not be precisely and literally true, but it's a good starting point.)

It is sometimes fine to have different modules doing the same job. For example, the more arrows in your access-control quiver, the better. But don't let more than one mod issue redirects.

not2easy

10:45 pm on Jan 12, 2016 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



There is also good information in the Apache Forum Library to help you learn more about 301 best practices: [webmasterworld.com...]

ergophobe

11:18 pm on Jan 12, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't think there's any "perhaps" about it


Actually, it's still a "perhaps." I said *perhaps* it's rewriting the original request. I don't know that and that, I imagine, is why only one of the redirects is failing. The others are not being rewritten and so they pass on to mod_alias untouched and work, whereas one of them gets rewritten along the way and the match therefore doesn't work as expected.

As I don't know what all his rules are, I can only guess that's what's happening... perhaps

Anyway, the point remains the same: do not cross the streams!