目前,我在网站上使用带下划线的连字符301,效果很好,但我还想将所有链接都转换为小写,并将大写添加为小写重写。
我可以执行此操作,但是使用当前方法,它可以执行以下操作,但我认为这对SEO不太好:
如何将以下重写组合到一个查询中,以便带有下划线或大写字母的网址通过301转换为连字符和小写字母?
下划线连字符重写
RewriteRule ^post/([^_]*)_([^_]*_.*)$ /posts/new-category-1/$1-$2 [L,NE]
RewriteRule ^post/([^_]*)_([^_]*)$ /posts/new-category-1/$1-$2 [L,NE,R=301]
RewriteRule ^forum/([^_]*)_([^_]*_.*)$ /forums/new-category-1/$1-$2 [L,NE]
RewriteRule ^forum/([^_]*)_([^_]*)$ /forums/new-category-1/$1-$2 [L,NE,R=301]
大写到小写重写
httpd.conf
RewriteMap lc int:tolower
.htaccess
RewriteCond %{REQUEST_URI} ^[^A-Z]*[A-Z].*
RewriteRule ^ ${lc:%{REQUEST_URI}} [L,R=301]
您可以301
通过以下规则来避免多个:
RewriteRule ^(post|forum)/([^_]*)_([^_]*_.*)$ /$1/$2-$3 [L,NE]
# if there is any upper case letter then do both lowercase conversion AND
# underscore to hyphen replacement
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(post|forum)/([^_]*)_([^_]*)$ /${lc:$1}/${lc:$2}-${lc:$3} [L,NE,R=301]
# otherwise regular underscore to hyphen replacement
RewriteRule ^(post|forum)/([^_]*)_([^_]*)$ /$1/$2-$3 [L,NE,R=301]
# and regular lower case conversion
RewriteRule ^(post|forum)/[^A-Z]*[A-Z] ${lc:%{REQUEST_URI}} [L,R=301]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句