我正在尝试向我的 .htaccess 添加一些代码,以将斜杠和非斜杠 url 重定向到 .html 所有 url,除了我的主页。
例如 www.mydomain.com/cat/ 和 www.mydomain.com/cat 应该重定向到 www.mydomain.com/cat.html
我设法将以下内容添加到我的 .htaccess 中,它将 www.mydomain.com/cat 重定向到正确的位置 www.mydomain.com/cat.html 但需要一些有关如何使斜杠版本重定向到 .html 页面的帮助
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mydomain.com/$1.html [R=301,L]
我的整个 .htaccess 看起来像这样,如果有人根据上述内容对它的外观有任何建议,将不胜感激。
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxx.xxx.xxx.xx [nc,or]
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mydomain.com/$1.html [R=301,L]
DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
RewriteEngine on
# Pleas note that RewriteBase setting is obsolete use it only in case you experience some problems with SEO addon.
# Some hostings require RewriteBase to be uncommented
# Example:
# Your store url is http://www.yourcompany.com/store/cart
# So "RewriteBase" should be:
# RewriteBase /store/cart
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !\.(png|gif|ico|swf|jpe?g|js|css)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php?sef_rewrite=1 [L,QSA]
</IfModule>
已解决:我刚刚添加了:
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$ /$1 [R=301,L]