[英]How to add trailing slash to end of URL
这是我的.htaccess
文件:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule !\.(css|js|ico|zip|rar|png|jpg|gif|pdf)$ index.php [L]
AddType application/x-httpd-php .php .phtml
并且当我有以下代码时,我需要知道如何在URL末尾添加斜杠:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
用于在.htaccess
添加www
示例,例如没有此代码的URL:
www.example.com/introduction
并使用以下代码:
www.example.com/introduction/
有这种方式:
AddType application/x-httpd-php .php .phtml
RewriteEngine On
RewriteBase /
# add www
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# add a trailing slash to non-files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(css|js|ico|zip|rar|png|jpe?g|gif|pdf)$ index.php [L,NC]
IIS用户的规则:添加/到所有URL。 为所有seo工作
<rule name="Add trailing slash" stopProcessing="true">
<match url="^(.*)([^/])$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="(.*?)\.[a-zA-Z]{1,4}$" negate="true" />
</conditions>
<action type="Redirect" url="{R:0}/" redirectType="Permanent" />
</rule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.