【问题标题】:Double slash in url after domain name [Kohana]域名后 url 中的双斜杠 [Kohana]
【发布时间】:2015-10-23 11:26:24
【问题描述】:

我对 Kohana 框架中的 URL 有疑问。

当我输入 mydomain.xyz/admin 时,重定向到 mydomain.xyz//admin 并从 Kohana 核心返回一些错误。

这是我.htacces的一部分:

RewriteEngine On
RewriteBase /

RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L]

###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ $1/ [R=301,L]

RewriteRule ^(.*)public_html/index.php/(.*)$ http://mysite.xyz/$1$2 [R=301,L]

从其他服务器移动站点后出现该问题。

【问题讨论】:

    标签: .htaccess url mod-rewrite kohana


    【解决方案1】:

    这样吧:

    DirectorySlash Off
    RewriteEngine On
    RewriteBase /
    
    ###### Add trailing slash (optional) ######
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
    
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteRule ^(.*)public_html/index.php/(.*)$ /$1$2 [R=301,L,NE]
    
    RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
    RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L,QSA]
    

    确保在测试此更改之前清除浏览器缓存。

    【讨论】:

    • 我试过了。那是行不通的。当我输入mysite.xyz 时,将其重定向到mysite.xyz// 并给出错误:ERR_TOO_MANY_REDIRECTS
    • 好吧,硬清除缓存有帮助。但现在出现了其他错误:当我在管理页面输入登录名和密码时,下一步就没有了。页面只是重新加载。在浏览器控制台中,我看到日志:Failed to clear temp storage: It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources. SecurityError。在更改 .htaccess 之前,当我手动删除正在工作的第二个斜杠时。
    • 好的,这行得通。非常感谢! :) 所以只有 Ctrl+Shift+R(例如 Google Chrome)刷新没有帮助?
    • 是的,即使在不同操作系统的同一浏览器上,浏览器的行为也会有所不同。
    猜你喜欢
    • 2016-06-04
    • 2018-03-18
    • 1970-01-01
    • 2012-06-19
    • 2016-11-21
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多