[英]Add Trailing Slash to Posts
我正在使用以下 .htaccess 代码添加斜杠除主页之外的所有网址。
## Base Redirects ##
# Turn on Rewrite Engine
RewriteEngine On
# Include trailing slash on non-filepath urls
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ https://hamilekadin.net/$1/ [R=301,L]
# Remove trailing slash from directory
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)/$ https://hamilekadin.net/$1 [R=301,L]
# Force HTTPS and remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [OR,NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://hamilekadin.net/$1 [R=301,L]
我想要非 www 网址、https 协议和帖子和页面网址后的斜杠。
有了这个 .htaccess,我在类别、页面、帖子上遇到404 错误。
我的永久链接类型也是: /%postname%/
这是斜杠的代码
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://yourdomainname.com/$1 [L,R=301]
对于非www url,有两种选择
选项1:
您需要运行 SQL 查询以从 url 中删除 www
选项 2
在.htacess 中添加以下代码
RewriteCond %{HTTP_HOST} ^www. yourdomain\.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com $1 [L,R=301,NC]
据我说,删除 www 最可取的方法是选项 1,您只需要运行查询即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.