Welcome to WebmasterWorld Guest from 34.238.192.150

Forum Moderators: Ocean10000 & phranque

How to do 301’s with new keywords in URLs + redirect www to https?

     
10:50 pm on Aug 7, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


I’m moving a 180 page html non https site over to WordPress and to https AND changing the keywords of the permalinks after the domain name in the URLs in an .htaccess file in Apache. I'm keeping the root domain name the same, my new site is now on a test server.

Some of the old files I'm moving are http: //www.site.com/keyword-abc.html

AND sadly some of the old files are duplicates of those files but not www. I.e., http: //site.com/keyword-abc.html

So I need to manually find some way to list both the html files http: //www.site.com/keyword-abc.html

And the

http: //site.com/keyword-abc.html

And redirect it not only to https but also change the URL after the domain name like

https: //site.com/new-keyword-that-ranks/

I don’t want to use a WordPress plugin to do it but .htaccess file in Apache.

How to I write the code for moving both the www and the non www insecure urls to https and totally different keywords in the htaccess file and not have chains of redirects?

I know I will have to write a line of code or two for each URL I want to change.

Does it matter if I do the http: //www.site.com/keyword-abc.html first before the http: //site.com/keyword-abc.html in the redirect?

If I put a space between each URL change to be able to see and trouble shoot it easier, will that affect the speed of the redirects or cause any problems?

I’ve gone over lots of tutorials for .htaccess and have never seen any of them that does both a www non secure to https redirect, AND an http:// no www to https redirect AND different keywords in the new URL after the domain name

I think the hard part is the different keywords after the domain name but I've already built the site with those URLs in it.

Thanks
10:53 am on Aug 25, 2019 (gmt 0)

Senior Member

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

joined:July 3, 2006
posts: 3153
votes: 7


Maybe it will help to look at it this way...


RewriteRule ^adhdmedicationart\.html$ https://example.com/adhd-medication-articles/ [R=301,L]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]


These directives effectively work like this (pseudo-code)....


IF (URL-PATH is "adhdmedicationart.html") THEN
Redirect to "https://example.com/adhd-medication-articles/"

ELSE
IF (HTTPS is "off" OR HTTP_HOST is not "example.com") THEN
Redirect to "https://example.com/<SAME URL-PATH AS REQUESTED>"


As I've tried to illustrate above.... if the requested URL-PATH matches your first RewriteRule directive then the redirect is triggered and the second rule block is effectively bypassed - it does not need to be processed - there is nothing more to do. This is why the tool states "This rule was not met" - which is what you want to happen.

Now reverse the above and maybe you'll see why you were getting the result you were getting. (?)
5:54 am on Aug 26, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


Ah, now I get it. Thanks penders.

So because I'm rewriting every single url, where the keywords after the domain name are ALL different, this last bit of code won't work, the RewriteRule, since it keeps the old end trailing keywords, which will just 404 it, because every new URL has a different post domain name keyword string.

RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

So do I need this Rewrite rule at all?

Should I just delete it and leave the code like this, which seems to work?

The Request URL
http://www.example.com/addintheworkplacearticles.html


RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/ [R=301]

RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)?$

Results.

Output url

https://example.com/manage-adhd-at-work/

Debugging info

1RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/ [R=301]The new url is https://example.com/manage-adhd-at-work/
Test are stopped, a redirect will be made with status code 301

2RewriteCond %{HTTPS} =off [OR]This rule was not met.

3RewriteCond %{HTTP_HOST} !^(example\.com)?$This rule was not met.
7:23 am on Aug 26, 2019 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11871
votes: 245


So do I need this Rewrite rule at all?

Should I just delete it and leave the code like this, which seems to work?

try testing this url:
http://www.example.com/manage-adhd-at-work/

then you will understand why you need those rules, all of them, in the order that has been described several times in this thread.
5:08 am on Aug 29, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


Hi phranque, I tried doing that code.

While it worked in the madewithlove htaccess tester, it did not work on my web server.

Talked to my host and they suggested this simple code instead.

RewriteEngine On

Redirect 301 "/addintheworkplacearticles.html" https://example.com/manage-adhd-at-work/

and that worked perfectly fine.
5:45 am on Aug 29, 2019 (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:15934
votes: 888


Talked to my host and they suggested this simple code instead.

RewriteEngine On
Redirect 301 etcetera
Your host suggested the “RewriteEngine on” directive followed by a mod_alias rule? Your host is an idiot and should not be allowed near a server.
8:24 am on Aug 29, 2019 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11871
votes: 245


I’m moving a 180 page html non https site over to WordPress...

Talked to my host and they suggested this simple code instead.

RewriteEngine On

Redirect 301 "/addintheworkplacearticles.html" https://example.com/manage-adhd-at-work/

and that worked perfectly fine.

try this and you will discover you have a problem when you combine mod_alias and mod_rewrite directives:
http://www.example.com/addintheworkplacearticles.html
will redirect to:
https://example.com/addintheworkplacearticles.html
and when your browser subsequently requests that url you will finally get redirected to:
https://example.com/manage-adhd-at-work/

this is assuming you still have the general hostname canonicalization redirect in place.
and if you don't your host's suggestions were both wrong and insufficient.

the reason this happens is as follows:
The use of RewriteRule to perform this task may be appropriate if there are other RewriteRule directives in the same scope. This is because, when there are Redirect and RewriteRule directives in the same scope, the RewriteRule directives will run first, regardless of the order of appearance in the configuration file.

source: [httpd.apache.org...]

keep in mind that you will always have "other RewriteRule directives in the same scope" when you are using WordPress because WP requires mod_rewrite to do the internal rewrite of the requested path to the WP script.
10:03 am on Aug 30, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


Thanks lucy24 and phranque. I passed that onto them and they changed it. Here's the new code.

RewriteEngine on
Redirect 301 /addintheworkplacearticles.html https://example.com/manage-adhd-at-work/

I tested it in madewithlove and here are the results.

Output url

https://example.com/manage-adhd-at-work/

Debugging info

1RewriteEngine onRewriteEngine was now turned on
2Redirect 301 /addintheworkplacearticles.html https://example.com/manage-adhd-at-work/
The new url is https://example.com/manage-adhd-at-work/
Test are stopped, a redirect will be made with status code 301

And put the old website in screaming frog to be crawled and it seemed to work. No chain redirects like the page rank damaging last one, thanks for catching that.

Here's the screaming frog redirects and canonical chains report.

Chain Type was HTTP Redirect.
Number of Redirects was 1
Redirect Loop was false

Address was http://www.example.com/addintheworkplacearticles.html
Status Code was 301
Final address was https://example.com/manage-adhd-at-work/

Status Code was 301
Status 1 was Moved Permanently
Redirect Type was HTTP Redirect
10:23 am on Aug 30, 2019 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11871
votes: 245


Here's the new code.

RewriteEngine on
Redirect 301 /addintheworkplacearticles.html https://example.com/manage-adhd-at-work/

is that all of your new code?
10:34 am on Aug 30, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


yes that's all the code they did.

The rest is 160 or so individual redirects. I've tested them and it works with both the old html files

http://example.com/addintheworkplacearticles.html

and the

http://www.example.com/addintheworkplacearticles.html

and redirects them both to

https://example.com/manage-adhd-at-work/
10:48 am on Aug 30, 2019 (gmt 0)

Senior Member

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

joined:July 3, 2006
posts: 3153
votes: 7


I passed that onto them and they changed it. Here's the new code.

RewriteEngine on 
Redirect 301 /addintheworkplacearticles.html https://example.com/manage-adhd-at-work/



Changed what? (Removing the quotes from around the source URL changes nothing - since they are optional anyway in this instance.)
11:12 am on Aug 30, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


crap. I thought if it didn't show up as a chain redirect in screaming frog it would be OK and not do what you said here:(

"try this and you will discover you have a problem when you combine mod_alias and mod_rewrite directives:
http://www.example.com/addintheworkplacearticles.html
will redirect to:
https://example.com/addintheworkplacearticles.html
and when your browser subsequently requests that url you will finally get redirected to:
https://example.com/manage-adhd-at-work/"
6:57 am on Aug 31, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


So my hosting company finally escalated the 301 problem to a senior tech.

They seemed to have fixed it. Even though made for love tester says it doesn't work.

Final code is only single lines of redirects. No “RewriteEngine On” statements at all or any other code.

Like this

Redirect 301 /adhd-coaching/coachingandaddarticles.html https://example.com/adult-adhd-coaching-articles/

Redirect 301 /adhd-coaching/careers-of-adhd-adults-i-have-coached.html https://example.com/careers-of-adhd-adults-coached/

Here’s what they said.

“I’m testing with the following redirect:

Redirect 301 /adhd-coaching/coachingandaddarticles.html https://example.com/adult-adhd-coaching-articles/

Note that the mod_rewrite "RewriteEngine On" statement is not required when using "Redirect 301" statements. This looks to be working properly, with only one redirect:

$ curl -IL https://www.example.com/adhd-coaching/coachingandaddarticles.html
HTTP/1.1 301 Moved Permanently
Date:
Server: Apache
Location: https://example.com/adult-adhd-coaching-articles/
Vary: Accept-Encoding
Content-Type: text/html; charset=iso-8859-1


I'm seeing the same results using HTTP vs HTTPS, or www vs non-www.

I would recommend implementing the remaining redirects using just "Redirect 301" statements.”

And I tried it with several redirects and all worked, and worked quicker than before.

But when I try it in madewithlove tester it didn't work.

http://www.example.com/adhd-coaching/coachingandaddarticles.html

Redirect 301 /adhd-coaching/coachingandaddarticles.html https://example.com/adult-adhd-coaching-articles/

Debugging info

1Redirect 301 /adhd-coaching/coachingandaddarticles.html https://example.com/adult-adhd-coaching-articles/This redirect was not followed.

What do you think of that code?
4:35 pm on Aug 31, 2019 (gmt 0)

Senior Member

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

joined:July 3, 2006
posts: 3153
votes: 7


But when I try it in madewithlove tester it didn't work.


FWIW, that would seem to be a bug with the madewithlove tester.
4:58 pm on Aug 31, 2019 (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:15934
votes: 888


This redirect was not followed.
Why are you interpreting this as an error? A robot, unlike a human browser, is not required to follow-up on a redirect. (But like human browsers, robots are not able to barge through and pick up the originally requested URL; that's never an option with redirects.) They're simply noting its existence.

Honestly I think you're worrying too much about tools of questionable utility. There is a place for validators--notably the w3 trio of html, css and link checker--but beyond that, you're better off requesting some random pages on your own and verifying that the redirect goes through in a single step. Use your browser's header-checking utility (such as Live Headers) for this part.
5:16 am on Oct 3, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


Thanks penders did not know it was a bug in madewithlove tester.
5:21 am on Oct 3, 2019 (gmt 0)

New User

Top Contributors Of The Month

joined:Aug 7, 2019
posts: 31
votes: 0


Hi Lucy24,

I'm relying on the tools because I've never done 301's before and have a healthy fear from all the articles of screwing up my site and/or the rankings. I don't know what else I should rely on.

re: " Use your browser's header-checking utility (such as Live Headers) for this part." Ok how do I do this? I googled it and couldn't find anything that explained how to do it that I could do.
5:06 pm on Oct 3, 2019 (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:15934
votes: 888


It depends on your browser; typically it's an add-on.

If all else fails, test some pages and then look at your raw logs to verify that each requests gets only a single 301 response followed by a 200 at the new URL.
6:05 pm on Oct 3, 2019 (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:4558
votes: 363


If you are seeking instructions and tool suggestions, you might be better off asking that question in the browser forum [webmasterworld.com] related to your browser. Then people can tell you what to use and how to use it. ;)
This 78 message thread spans 3 pages: 78