質問

Brief background: Our Knowledgebase has about 200 articles and although each article can have various URL's that all contain a canonical link to what we prefer Google to index. Canonical links are working properly but post hummingbird, google has started to drop many of the canonical links for other URL formats available for that article in the FAQ. Nothing had changed and all other sections of the site are working properly.

We will continue to research why this is happening, but in the mean time the best route is to 301 all URL's for a specific article to the desired (canonical) url. We have had no success at all in trying different methods due to the other content in our htaccess file. It is is ending up in a loop of some sort.

Please allow me to share the requirements we have and then post our htaccess so we can hopefully change it as required.

REQUIREMENTS

Force non secure for all URL's (Redirect all https to http with 301) - already working in htaccess Redirect non www to www - already working in htaccess Redirect any URL's containing a specific director to a static URL - NOT WORKING

EXAMPLES OF ARTICLE REDIRECTION NEEDED

One specific article can have multiple URLS

  • /kb/article/AA-00333
  • /kb/article/AA-00333/0/
  • /kb/article/AA-00333/0/1/
  • /kb/article/AA-00333/0/article-title.html

We would want any URL that contains AA-00333 to be redirected to http://www.xyzdomain.com/kb/article/AA-00333/0/article-title.html

We can manually have an entry for each specific article in htaccess.

CURRENT HTACCESS

AddDefaultCharset UTF-8
DirectoryIndex index.php

#redirect articles
#RewriteEngine on
#RewriteRule .*AA-00333.* http://www.xyzdomain.com/kb/article/AA-00333/0/article-title.html [L,R=301]

#Redirect all secure to non secure https/http with 301
RewriteCond %{HTTPS} ^on$
RewriteRule ^(.*)$ http://www.xyzdomain.com/kb/$1 [R=301,L]

<IfModule mod_rewrite.c>
RewriteEngine On 
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^(www\.xyzdomain\.com)?$
RewriteRule ^(.*)$ http://www.xyzdomain.com/kb/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>
#
役に立ちましたか?

解決 2

Thank you so much for your suggestions everyone. None of those seemed to 100% work, so I played with all of our attempts and seemed to have found a solution

RewriteEngine on
RewriteCond %{REQUEST_URI} !0/article-title\.html$
RewriteRule .*AA-00333.* http://www.xyzdomain.com/kb/article/AA-00333/0/article-title.html [L,R=301]

It seems to be working for all test URLS, but if you see something wrong, please let me know.

Thank you again for your valuable insight. I LOVE this site and look forward to contributing as much as I can.

他のヒント

Is it that you need something like this?

RewriteCond %{REQUEST_URI} !article-title\.html$
RewriteRule ^kb/article/AA-00333 http://www.xyzdomain.com/kb/article/AA-00333/0/article-title.html [L,R=301]

The problem with what you have is that the destination URL also matches the regex patter, since it also contains a AA-00333 in it, causing a redirect loop. You noted that you wanted this to be redirected also but this causes a loop.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top