Forum Moderators: phranque

Message Too Old, No Replies

HELP 301s are adding a double slash and 404ing

         

TomSnow

8:40 pm on Dec 4, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



I set up redirect strings for htaccess like so:

Redirect 301 /blog/macintosh-apples /resources/apples/macintosh/

After launch, some 301s work, but many are doing this, which I've never seen:

/blog/apples/ redirects to /resources//macintosh/ (missing middle folder, replaced by double slash) which turns into /resources/macintosh apples (old slug) which is 404ing.

My strings all have the same formatting, so I don't know what's happening. Can't find a differentiation factor between the 301s that work and the ones with a double slash. Other than my geo pages don't have the double slash. My resource pages (articles) mostly do but some don't. My practice area pages mostly do but some don't.

Help!

Thank you :)

not2easy

4:28 am on Dec 5, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



First, if you have any RewriteRules in the .htaccess file and also use Redirect 301 with it you are likely to have unexpected results. Redirect 301 uses Mod_Alias and RewriteRule uses Mod_Rewrite. If the rules are in the wrong order of appearance in the .htaccess file they can cause more problems.

A few questions to determine the environment because it makes a difference:
1. Are there other rules/rewrites in the same htaccess file - maybe to canonicalize the www/non www and https to have a single URL?
2. Is this a WP site, with the typical WP snippet of code? That is, the lines that start out with
# BEGIN WordPress
<IfModule mod_rewrite.c>
3. Where are these redirects in relation to other rules?
4. What kind of server responses do you see in your logs when you try to access one of the redirected URLs?
5. Are these redirects from old URLs to new URLs on the same site or is this a site migration - and do the new URLs exist?

To research a little on your own, I can suggest a similar thread that could help explain some of this: [webmasterworld.com...]

No5needinput

4:32 pm on Dec 5, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



Don't the redirects as such have to be in the form of:

Redirect 301 /blog/macintosh-apples https://www.example.com/resources/apples/macintosh/


ie. Target needs to be the full uri

not2easy

5:01 pm on Dec 5, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Normally, but maybe not. If there are Mod_Rewrite Rules it should not be using the "Redirect 301" which is why we didn't get that far, waiting to hear what else is in there.

phranque

2:09 am on Dec 6, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Don't the redirects as such have to be in the form of:
...
ie. Target needs to be the full uri

no, they don't.
The new URL may be either an absolute URL beginning with a scheme and hostname, or a URL-path beginning with a slash. In this latter case the scheme and hostname of the current server will be added.

see: https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect

[edited by: phranque at 2:10 am (utc) on Dec 6, 2020]

phranque

2:10 am on Dec 6, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



waiting to hear what else is in there

i agree we shouldn't offer further solutions until the mod_rewrite usage question has been answered.


for more, see this from the apache documentation...
https://httpd.apache.org/docs/current/rewrite/avoid.html#redirect
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.


this usually means if you use mod_rewrite (RewriteRule) anywhere then you must use mod_rewrite everywhere instead of mod_alias (Redirect or RedirectMatch)