问题是斜杠/
“example.ru/aboutus/
”会转换为“ 500服务器错误”,并在uri末尾附加http://example.ru/aboutus/.html
。
## www.site/index.html ==> site/index.html ##
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^.*/index\.html
RewriteRule ^(.*)index.html$ /$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
## index.html ==> index ##
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
## index/ ==> index ##
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]
但是输入斜线,我会进入500页错误
in the html code pages do not have any links .html extension
`<a href=aboutus>About Us</a>` except `<a href=index.html>index</a>`
如何解决没有重复的问题,以便所有页面都没有斜杠和扩展名.html?所有这些都是seo所需要的
答案 0 :(得分:0)
找到了解决方案
Options All -ExecCGI -Multiviews -Indexes -Includes +FollowSymLinks
# This tag ensures the rewrite module is loaded
<IfModule mod_rewrite.c>
# enable the rewrite engine
RewriteEngine On
# Set your root directory
RewriteBase /
# remove the www extension
RewriteCond %{THE_REQUEST} ^.*/index\.html
RewriteRule ^(.*)index.html$ /$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# remove the .html extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
RewriteRule (.*)\.html$ $1 [R=301]
# remove index and reference the directory
RewriteRule (.*)/index$ $1/ [R=301]
# remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# forward request to html file, **but don't redirect (bot friendly)**
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.html [L]
</IfModule>