【问题标题】:htaccess removal of backslashhtaccess 去除反斜杠
【发布时间】:2018-04-29 03:57:22
【问题描述】:

我确定这个问题之前已经提出过,但我真的不知道要搜索什么。

当我单击该站点的外部链接时,我的 .htaccess 文件似乎正在删除“/”。 例如,当我点击“www.mysite.com/home”时,我会被定向到“www.mysite.comhome”

这是我的 .htaccess

# Turn mod_rewrite on
Allow from all
RewriteEngine On
Options +FollowSymLinks -MultiViews

ErrorDocument 404 /errors/404.php

DirectoryIndex home.php

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

RewriteCond %{REQUEST_METHOD}  !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(/{2,})(.*)$
RewriteRule . %1/%3 [R=301,L]

再次感谢!!

【问题讨论】:

    标签: php html .htaccess redirect


    【解决方案1】:

    问题是您尝试从 URL 中串起多个斜杠的最后一条规则。

    您可以在站点根目录 .htaccess 中使用这些规则:

    ErrorDocument 404 /errors/404.php
    DirectoryIndex home.php
    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    
    # To externally redirect /dir/foo.php to /dir/foo
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R=301,L,NE]
    
    # strip multiple slashes
    RewriteCond %{THE_REQUEST} //
    RewriteRule ^.*$ /$0 [R=301,L,NE]
    
    # To internally forward /dir/foo to /dir/foo.php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*?)/?$ $1.php [L]
    

    在测试此更改之前,请确保使用新浏览器以避免旧缓存或彻底清除浏览器缓存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-03
      • 2015-01-15
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多