Welcome to WebmasterWorld Guest from 18.232.171.18

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

joined:Aug 7, 2019
posts: 13
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:58 pm on Aug 7, 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:11771
votes: 225


welcome to WebmasterWorld [webmasterworld.com], endlesscuriosity!

please use example.com for domain names as explained in this pinned post:
IMPORTANT: Please Use example.com For Domain Names in Posts Apache Web Server forum at WebmasterWorld [webmasterworld.com]
11:35 pm on Aug 7, 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: 3131
votes: 3


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


Although that would arguably be the preferred/better way to do it. A redirection plugin prioritises "normal" site visitors (to the new site) and not the redirects from the old site. The redirection logic would be processed late, only on requests that would otherwise return a 404. Normal site visitors are not impacted in any way. However, if you use .htaccess then the redirection logic is processed on every single request to your new site, including all static resources - which is unnecessary. Ok, 180 redirect directives may not impact performance in this instance, but with a site of considerable size, a redirection "plugin" is really the only way to go.

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


Because there's really no difference. If you are redirecting from the old URL-path to the new then you are not concerned about whether the request was for www or non-www or HTTP or HTTPS. You always redirect to the canonical URL, ie. HTTPS and non-www (from your example).

[edited by: penders at 11:37 pm (utc) on Aug 7, 2019]

11:36 pm on Aug 7, 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:11771
votes: 225


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?
...
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?

you will redirect according to a pattern based on the requested path (/keyword-abc.html), regardless of the requested hostname, and you will provide the canonical protocol and hostname (https://www.example.com) in the target of the RewriteRule.
(btw not sure from your description if canonical hostname was www or non-www, so adjust accordingly)

you should order your redirect rulesets from most general to most specific, although it sounds like most of your redirects are one-to-one.
the general form of a one-to-one redirect would be similar to:
RewriteRule ^old-keyword\.html$ https://www.example.com/new-keyword/ [R=301,L]


after all the specific redirects you should have a general hostname canonicalization redirect.
there is some sample code for this in this thread:
Redirection to https://www. [webmasterworld.com]

remember to adjust for your canonical hostname (www or non-www) accordingly.


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?

putting a space between each ruleset is a good practice and will not have a measurable effect on your performance.

if you are wondering why i didn't give a more specific answer, please read the Apache Web Server forum Charter [webmasterworld.com]
11:52 pm on Aug 7, 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:15756
votes: 828


If I put a space between each URL change
By “space” do you mean a blank line? In configuration files--including htaccess--unlike robots.txt, blank lines have no syntactic meaning. You use them purely to preserve your own sanity and to make the file more readable. In addition to leaving blank lines, it's a very good idea to include
# explanatory comments
copiously, one before each rule or group of related rules.

Neither the hostname (with/without www) nor the protocol (http vs https) has any effect on redirects. The rule looks only at the URLpath.

If you are moving to WP (or any CMS), make sure all your RewriteRules come before the final WP section of htaccess. Otherwise they will never execute anyway. (Except perhaps in the rare case where the old file still physically exists on the server under its real name in its original location, which does not happen often.)
5:28 am on Aug 13, 2019 (gmt 0)

New User

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


Thanks Penders,

“Because there's really no difference. If you are redirecting from the old URL-path to the new then you are not concerned about whether the request was for www or non-www or HTTP or HTTPS. You always redirect to the canonical URL, ie. HTTPS and non-www (from your example).”

This is very useful. Did not know that.

Good point on the plugin but I still prefer the htaccess file.
5:35 am on Aug 13, 2019 (gmt 0)

New User

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


Thanks Phranque.

I used your rewrite rule to search and eventually found a great site with a .HtAccess 301 Redirect Generator Tool that allowed you to paste in your old and new urls and created the code for you. It allows you to force you to www, force you away from www, or do nothing and force to https or force to http.

Would this code do what I want?

Change all my old http://example.com and http://www.example.com to SSL and force https like https://example.com?

The code.

# Needed before any rewriting
RewriteEngine On


### Place after 'RewriteEngine On' and before any CMS specific rewrite rules

# Redirect HTTP with www to HTTPS without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
# Redirect HTTP without www to HTTPS without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS with www to HTTPS without www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]


## 301 Redirects
# 301 Redirect 1
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/? [R=301,NE,NC,L]

# 301 Redirect 2
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^adhdmedicationart\.html$ https://example.com/adhd-medication-articles/? [R=301,NE,NC,L]

# 301 Redirect 3
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^adhdmedicationco\.html$ https://example.com/adhd-medication-company-websites/? [R=301,NE,NC,L]

# 301 Redirect 4
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^timemanagement\.html$ https://example.com/time-management-articles-books-websites/? [R=301,NE,NC,L]

# 301 Redirect 5
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^communicationsskills\.html$ https://example.com/communications-and-social-skills-adhd/? [R=301,NE,NC,L]

[edited by: phranque at 5:51 am (utc) on Aug 13, 2019]
[edit reason] unlinked urls [/edit]

5:42 am on Aug 13, 2019 (gmt 0)

New User

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


Thanks Lucy24,

“By “space” do you mean a blank line?”

Yes I do.

“In addition to leaving blank lines, it's a very good idea to include
# explanatory comments copiously, one before each rule or group of related rules. “

Very good idea.

“If you are moving to WP (or any CMS), make sure all your RewriteRules come before the final WP section of htaccess. Otherwise they will never execute anyway”

Thanks, good to know, I’ve read a lot about http to https and a fair bit about .htaccess and did not read anything about that.

How would I place the 301 redirects in front of the WordPress ones? Just paste it at the top of the htaccess file? Other method?
6:13 am on Aug 13, 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:11771
votes: 225


The code.

# Needed before any rewriting
RewriteEngine On


### Place after 'RewriteEngine On' and before any CMS specific rewrite rules

# Redirect HTTP with www to HTTPS without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
# Redirect HTTP without www to HTTPS without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS with www to HTTPS without www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]

the general hostname canonicalization redirect should be placed after any more specific redirects but before the WP section.

you should combine these 3 rulesets into a single ruleset that does everything, specifying the canonical protocol and hostname in the target of the RewriteRule, similar to what was suggested in the thread i posted above:
# Redirect non-HTTP or non-www to HTTPS without www
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)$? [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]


## 301 Redirects
# 301 Redirect 1
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/? [R=301,NE,NC,L]

this is an example of a "more specific redirect" that should be placed before the general hostname canonicalization redirect.

i would assume you want this requested path to redirect regardless of the requested hostname.
also, if you are using the trailing ? in the RewriteRule target for the purpose of redirecting to a url without the query string then you probably want to do so when the query string exists and it is irrelevant if the query string is null.
in other words, i am guessing you would be safe to remove both conditionals from this ruleset.

if you don't need to applying hexcode escaping of special characters in the result of the rewrite, you can drop the [NE] flag.

you are probably okay with this:
# 301 Redirect 1
RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/? [R=301,NC,L]


similarly with the other 4 rulesets...
6:19 am on Aug 13, 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:11771
votes: 225


I’ve read a lot about http to https and a fair bit about .htaccess and did not read anything about that.

there are exceptions but generally the order should be:
- access control directives (for example rulesets using the [F] or [G] flags)
- external redirects, from most specific to most general (the most general being the hostname canonicalization ruleset)
- internal rewrites, from most specific to most general (an "internal rewrite" includes the WP ruleset)

How would I place the 301 redirects in front of the WordPress ones? Just paste it at the top of the htaccess file?

preceding the WP ruleset in .htaccess
5:23 am on Aug 14, 2019 (gmt 0)

New User

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


Thanks Phranque.

This is the reason why the person who created the redirect coding tool say he does the redirects differently than others.

“Why don't I use the shorter Redirect command

There is a lot simpler Redirect command that can do redirects in one line. e.g.
Redirect 301 /testsource.html /testdestination.html?a=b

The main reason I don't use it is because my tool is designed to do exact URL redirecting.

The Redirect command does not consider incoming query strings which means an exact source match can't be done. e.g. the above command will also match /testsource.html?parameter=value

Another limitation is that you can't restrict the source to a specific domain.

However you can specify the domain of the destination, and specify a query string (any source query string is always ignored and lost).”

But I don’t really understand his explanation.

I just use plain html url’s. I don’t do advertising, only do organic SEO, no UTM parameters in any of my URLs. I don’t send ezine with UTM parameters.

I don’t do ecommerce on the site, it’s just a lead generation site with a lot of free info and a landing page for a sample session.

Is there any reason why I should use his more complex rules for individual URL’s vs your simpler more direct one?
6:42 am on Aug 14, 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:15756
votes: 828


But I don’t really understand his explanation.
You have no idea how tempting it is to say “Don’t trouble your pretty little head about how or why; just do what phranque says.” If it were not past my bedtime I would give a fuller explanation, possibly including a discussion of why some parts of Redirect Coding Tool Guy’s own explanation are simply irrelevant. (Do you even have multiple domains sharing the same htaccess file?)

I just use plain html url’s. I don’t do advertising, only do organic SEO, no UTM parameters in any of my URLs. I don’t send ezine with UTM parameters.
Uh... what does any of this have to do with the mechanics of redirection? And where did “UTM parameters” come from?
6:43 am on Aug 14, 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:11771
votes: 225


“Why don't I use the shorter Redirect command ...


much of what he says is true but the most important reason not to use Redirect(Match) is this:
if you are using mod_rewrite directives anywhere in your .htaccess or server configuration files, you should use mod_rewrite everywhere, avoiding any mod_alias directives for redirect purposes.
this will help avoid chained redirects or exposing internal urls.

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...]
11:34 pm on Aug 14, 2019 (gmt 0)

New User

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


Hi Lucy24,

"(Do you even have multiple domains sharing the same htaccess file?)"

No I don't. Is that what his code is used for? vs the normal individual redirect?

"I just use plain html url’s. I don’t do advertising, only do organic SEO, no UTM parameters in any of my URLs. I don’t send ezine with UTM parameters."

"Uh... what does any of this have to do with the mechanics of redirection? And where did “UTM parameters” come from?"

I don't know why Tony McCreath who wrote the code that made it easy to batch convert old to new URL's one to one did it differently than others. He explained it like I posted here (was told not to paste any urls so I didn't) but I don't know enough about Apache code and server redirects to understand it. That's why I asked what it was for and if it's relevant to my situation.

I tried to list what my site was used for to see if it was relevant for me. I googled it, couldn't get an answer that explained it. I thought it might be about UTM parameters, or some kind of ecommerce settings.

I still don't know what it's for.
2:54 am on Aug 15, 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:11771
votes: 225


"(Do you even have multiple domains sharing the same htaccess file?)"

No I don't. Is that what his code is used for? vs the normal individual redirect?

these directives are written for generalized domains:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]


these directives are written for specific hostnames:
# 301 Redirect 1
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/? [R=301,NE,NC,L]

# 301 Redirect 2
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^adhdmedicationart\.html$ https://example.com/adhd-medication-articles/? [R=301,NE,NC,L]

...

and:
# Redirect non-HTTP or non-www to HTTPS without www
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)$? [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

and:
# 301 Redirect 1
RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/? [R=301,NC,L]
3:04 am on Aug 15, 2019 (gmt 0)

Senior Member from US 

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

joined:Nov 29, 2005
posts:10136
votes: 1010


@endlesscuriosity ... thanks for posting the OP.

@the players above: thanks for the info and insights! Actually answered a few of my questions for some projected changes.

Seriously, thanks!
3:52 am on Aug 15, 2019 (gmt 0)

New User

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


Thanks Phranque. I don’t think I need to or want to write mod_rewrite directives, and I don’t need one for generalized domains, only a specific one.

So using your code, would this be the right code for me?

# step one list every individual redirect which would include both the old http://example.com and http://www.example.com individual pages to the new https://example.com individual pages.

# 301 Redirect 1
RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/? [R=301,NC,L]

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

# 301 Redirect 3
RewriteRule ^adhdmedicationco\.html$ https://example.com/adhd-medication-company-websites/? [R=301,NC,L]

# continue step one all the other individual page to page redirects, then

# Redirect non-HTTP or non-www to HTTPS without www
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)$? [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

Then

WordPress htaccess code?
3:55 am on Aug 15, 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:15756
votes: 828


@endlesscuriosity:
OK, here's the not-yet-bedtime version (edit: It looks as if we overlapped):

#1 The Apache web server is made up of lots of separate modules, each of which has its own particular tasks. Some of them involve things you can set in htaccess; others work quietly behind the scenes where you can't see them. Every time a request comes in, all the modules do their various things, one after the other, in a fixed order that you can't change. Each module is an island; when its turn comes up, it runs through your htaccess file, picking up all directives that apply to it, and ignoring all others. This means that it doesn't make any difference if your directives for Module A come after Module C, before Module B, or all mixed in at random. The only thing that matters is order within any given module. If you want a rough-and-ready rule: modules tend to execute in reverse alphabetical order.

#2 There are two different modules that can issue redirects: mod_alias, with the directives
Redirect
RedirectMatch
and mod_rewrite, with the directive
RewriteRule
possibly preceded by one or more
RewriteCond.
(Fun fact: It doesn't matter where you put the line RewriteEngine On; it will be read regardless. I think it was penders or someone like him who did the research.) Those RewriteCond options mean that only mod_rewrite can look at things other than the URLpath: protocol (http/https), hostname (with/without www, or subdomains), parameters (query string), environmental variables, cookies, et cetera et cetera.

#3 Because of #1, any directives for mod_alias (Redirect by that name) will always execute after directives for mod_rewrite (RewriteRule, including but not limited to redirects). Since mod_alias is more limited in the kinds of redirects it can issue, this in turn means that some requests might be redirected twice.

With me so far?
4:11 am on Aug 15, 2019 (gmt 0)

New User

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


Thanks Lucy, yes, looks like I might be risking redirect chains and page rank damage if I use mod_rewrite. Or at least with double redirects, slowing things down. So no need for me to use that. Best to stir to regular redirects.
6:07 am on Aug 15, 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:11771
votes: 225


So using your code, would this be the right code for me?

yes.
the only thing i would add, to your comment, is that the individual redirects will erase any query string from the request (i.e., there is a trailing '?' in the target)
Then

WordPress htaccess code?

yes.
6:08 am on Aug 15, 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:11771
votes: 225


looks like I might be risking redirect chains and page rank damage if I use mod_rewrite. Or at least with double redirects, slowing things down. So no need for me to use that. Best to stir to regular redirects.

no, it is the mixed usage of mod_alias and mod_rewrite that may expose internal urls and/or cause chained redirects.
therefore, since you must use mod_rewrite for WP, you want to avoid using mod_alias for any redirects and instead use mod_rewrite exclusively.

please reread my quote from apache's documentation posted previously in this thread.
6:23 am on Aug 15, 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:11771
votes: 225


#3 Because of #1, any directives for mod_alias (Redirect by that name) will always execute after directives for mod_rewrite (RewriteRule, including but not limited to redirects).


for example, if you are using mod_alias for the specific redirects and you request http://www.example.com/manage-adhd-at-work/addintheworkplacearticles.html the first redirect that fires is the mod_rewrite directives for redirecting to https/non-www which will redirect the first request to https://example.com/manage-adhd-at-work/addintheworkplacearticles.html and the subsequent request will fire the mod_alias directives
which will redirect the second request to https://example.com/manage-adhd-at-work/
6:40 am on Aug 15, 2019 (gmt 0)

New User

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


Thanks phranque,

I see, no need to mix modrewrites and rewrites , I will just use regular redirects instead.

I don't have a ? at the end of my url just this https://example.com/manage-adhd-at-work/

I still don't know what query string from the request are for.

Hopefully I don't need them.

It was his code that added the ? at the end of the URL. https://example.com/manage-adhd-at-work/?

So I should do it like this instead?

# 301 Redirect 1
RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/ [R=301,NC,L]

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

Thanks
6:41 am on Aug 15, 2019 (gmt 0)

New User

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


You're welcome tangor
4:26 pm on Aug 15, 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:15756
votes: 828


I will just use regular redirects instead
Please stop saying “regular redirects”. It is by no means clear what you mean.
11:35 pm on Aug 15, 2019 (gmt 0)

New User

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


I think I want mod_alias 301 redirects. Just to go from one permalink URL to a new one. I don't think I need mod_rewrite redirects.
12:15 am on Aug 16, 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:4396
votes: 314


If you can figure out how to convince WP to alter it's directives to use mod_alias, go for it.

If you plan to use WP, get used to the idea of using mod_rewrite or be prepared for recurring problem solving. As mentioned several times in the previous explanations, mod_alias does not work as expected in combination with mod_rewrite. WP uses mod_rewrite. The order of rules matters and your page-URL rewrites need to come before the HTTPS/non-www and WP rules. It is best to avoid problems whenever possible rather than build them in to your website.
1:40 am on Aug 16, 2019 (gmt 0)

New User

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


OK, now I'm getting confused.

If my goal is to get my old site with my files with both http://example.com and http://www.example.com to move to my new SSL site with no www but this instead, https://example.com and redirect each individual URL like

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

to http://www.example.com/manage-adhd-at-work/

Is this the correct code to make it happen?

# 301 Redirect 1
RewriteRule ^addintheworkplacearticles\.html$ https://example.com/manage-adhd-at-work/ [R=301,NC,L]

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

# 301 Redirect 3
RewriteRule ^adhdmedicationco\.html$ https://example.com/adhd-medication-company-websites/ [R=301,NC,L]

# continue this on all the other individual page to page redirects, then paste this code after it

# Redirect non-HTTP or non-www to HTTPS without www
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)$? [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

than after that code, put the WordPress htaccess code?
2:50 am on Aug 16, 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:15756
votes: 828


You don't need the [NC] flag.

To your human brain, case-changing is trivial. But to the server, it means that every incoming request has to be converted to lower-case (i.e. identify alphabetic characters and then add some number--32, I think, for Latin--to its numeric code) before it is evaluated against the pattern. It's only worth it if at some point in the past you goofed, so there really are variably cased URLs floating around. Otherwise, if someone's asking for a filename with the wrong casing, that's their problem, not your server's. (In practice, I only see it when the bingbot requests example.com/lowercase.html when it should be example.com/CamelCase.html. Wrongly cased requests from unwanted robots don't count.)

then after that code, put the WordPress htaccess code?
Yup. Make sure you leave the WP comment lines--not2easy probably knows the exact formula--because that’s what WP looks for whenever you upgrade.
3:15 am on Aug 16, 2019 (gmt 0)

New User

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


OK I went over my old URL's all lower case. So I removed the NC from each individual redirects to avoid this

"Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear as upper-case or lower-case in the matched URI."
[httpd.apache.org...]

and removed the NC from this line below.

RewriteCond %{HTTP_HOST} !^(example\.com)$?

Here's the new code, look good?

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

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

# 301 Redirect 3
RewriteRule ^adhdmedicationco\.html$ https://example.com/adhd-medication-company-websites/ [R=301,L]

# continue this on all the other individual page to page redirects, then paste this code after it

# Redirect non-HTTP or non-www to HTTPS without www
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)$?
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

than after that code, put the WordPress htaccess code
This 34 message thread spans 2 pages: 34
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members