.htaccess删除尾部斜杠

.htaccess删除尾部斜杠,.htaccess,redirect,.htaccess,Redirect,我有一个网站的htaccess文件,让它的脚本工作。我不知道它是如何工作的,但我必须删除末尾的尾随斜杠 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?/$1 [L] RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_

我有一个网站的htaccess文件,让它的脚本工作。我不知道它是如何工作的,但我必须删除末尾的尾随斜杠

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

ErrorDocument 404 https://www.onlinegames.nl/

## 301 Redirects
# 301 Redirect 1
RewriteCond %{HTTP_HOST}  ^www\.onlinegames\.nl$ [NC]
RewriteCond %{QUERY_STRING}  ^$
RewriteCond %{HTTPS} =on
RewriteRule ^index\.html$ https://www.onlinegames.nl/? [R=301,NE,NC,L]

<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>
重新编写引擎打开
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php?/$1[L]
重写条件%{HTTPS}关闭
重写规则。*https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
重写规则。*https://www.%{HTTP_HOST}%{REQUEST_URI}[R=301,L]
错误文档404https://www.onlinegames.nl/
##301重定向
#301重定向1
重写COND%{HTTP_HOST}^www\.onlinegames\.nl$[NC]
重写cond%{QUERY_STRING}^$
RewriteCond%{HTTPS}=on
重写规则^index\.html$https://www.onlinegames.nl/? [R=301,东北,北卡罗来纳,北卡罗来纳]
标题集访问控制允许原点“*”

如何删除结尾处的尾随斜杠?我试图更改一些内容,但大多数情况下,脚本不再正常工作,所有子页面也不再正常工作。

您可以在站点root.htaccess中使用这些规则来替换显示的代码。请注意,这些规则的顺序也很重要,并在
ErrorDocument
中进行更改

ErrorDocument 404 /

RewriteEngine On

# remove www from host names
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# redirect http to https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/+$
RewriteRule ^ %1 [R=301,NE,L]

# strip /index.html
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.html$ / [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]

删除尾部斜杠会更改URL路径的文件夹深度。因此,任何相对URL(与域根不相关)都可能需要修改。删除尾部斜杠的原因是什么?你能添加一些例子吗?我对此不太了解,但他们让我重定向到只有一个版本,并且在末尾有非尾随斜杠。你说的“不工作”到底是什么意思?所有的内部链接都没有尾部斜杠吗?(您现有的指令顺序错误。您的404将触发主页的302-这通常对用户和搜索引擎有害。)谢谢,这确实解决了问题。知道ErrorDocument必须在顶部也很好。@WouterdenOuden ErrorDocument不必“在顶部”-尽管从可读性的角度来看,在文件的早期定义错误文档更符合逻辑。但是,mod_重写规则的顺序很重要。