Welcome to WebmasterWorld Guest from 35.172.100.232

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

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

Junior Member

10+ Year Member

joined:Nov 24, 2005
posts: 178
votes: 0


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.
8:26 pm on Jan 12, 2016 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4453
votes: 330


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.
8:46 pm on Jan 12, 2016 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 24, 2005
posts: 178
votes: 0


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.
9:05 pm on Jan 12, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8637
votes: 283


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.
9:17 pm on Jan 12, 2016 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 24, 2005
posts: 178
votes: 0


OK thanks not2easy and ergophobe. Now I understand what you mean. I have some studying to do on mod_rewrite rules.
9:28 pm on Jan 12, 2016 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15804
votes: 845


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.
10:45 pm on Jan 12, 2016 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4453
votes: 330


There is also good information in the Apache Forum Library to help you learn more about 301 best practices: [webmasterworld.com...]
11:18 pm on Jan 12, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8637
votes: 283


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!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members