从目录中删除尾部斜杠

时间:2021-01-20 19:09:43

标签: .htaccess redirect slash trailing

是否可以删除共享主机中的尾部斜杠?我完全知道有一堆关于从目录中删除尾部斜杠的 StackOverFlow 线程,到目前为止我尝试了大约 15 个以上,但都没有工作。一个接近的是 301 重定向。但是,输入后,我收到了太多重定向错误。 也许其他人处理过这个问题并知道这是否可能?

基本上,我想要做的是,使 URL domain.com/test/ 转到 domain.com/test

到目前为止我尝试过的(大部分我尝试过的都是 .htaccess 规则):

RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} /(.+?)/+[?\s]
RewriteRule ^(.+?)/$ $1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

<IfModule mod_rewrite.c>
    RewriteEngine On            
    RewriteBase /test

    RewriteRule (.*)/$ $1 [R,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f         
    RewriteRule ^(.*)$ index.php?url=$1 [PT,L] </IfModule>

Options +FollowSymLinks -MultiViews

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^\.]+)$ $1.php [NC,L] RewriteRule ^test$ /test/index.php [L,E=LOOP:1]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

RewriteEngine on
RewriteRule (.+)/$ /test/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Trailing slashes and .html suffix RewriteCond !/$ RewriteCond !\.php$

# Check if it's actually a dir and if index.php exists RewriteCond %{REQUEST_URI} -d RewriteCond %{REQUEST_URI}/index.php -f

# Rewrite anything that gets through (Probably insecure, but you get the idea) RewriteRule ^(.*)$ $1/index.php

RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{REQUEST_URI} !^/test(.*)?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RedirectMatch 301 ^(.+)/$ $1

这是最接近的一个,但是,如前所述,我收到了太多重定向错误。

我尝试了许多其他代码,此时我确信这是不可能的。我也尝试了隐身模式和代理站点下的所有内容,以避免缓存。尝试将每个代码添加到主 public_html .htaccess 并测试 .htaccess。如果有帮助,也尝试启用 SymLinks。测试文件夹只包含 index.php

有什么想法吗?谢谢。

0 个答案:

没有答案