[英]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.