问题
I have a lot incorrect back links, the links are pointing to:
http://www.domain.com/tags/keyword
while the correct path is
http://www.domain.com/tags/keyword/
there are hundreds of those...how could i 301 redirect from the wrong links to the correct links?
Thank you so much in advance
回答1:
You can try this code:
RewriteBase /
RewriteRule ^tags/([^/]+)$ /tags/$1/ [L,R=301]
RewriteBase /
tells apache that your URI starts by a/
. If your site was in a subfolder you should writeRewriteBase /subfolder/
instead.^tags/([^/]+)$
: you search for an URI starting withtags/
followed by[^/]+
that means any characters except/
. The( )
around it are there to capture it and use it in the redirection. So we capture any characters that are not/
betweentags/.../
in the URI. (^
marks the start of the string while$
marks the end)/tags/$1/
is the redirection.$1
means the first previous captured element (the one witch was between( )
).[L,R=301]
indicates to apache that it should stop process other rules and redirect with a 301 header code.
来源:https://stackoverflow.com/questions/35033190/301-redirect-to-full-path