【问题标题】:.htaccess and trailing slash in CodeIgniterCodeIgniter 中的 .htaccess 和斜杠
【发布时间】:2015-11-27 11:48:30
【问题描述】:

在我的配置文件中,我有:

$config['url_suffix'] = "/"; 

这是我的 .htaccess:

    Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}      ^.+[^/]$
RewriteRule ^(.+)$              $1/   
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

当我加载页面时,我没有看到尾部斜杠。我正在使用 URI 路由,但即使我转到控制器/视图的实际路径,我仍然没有得到尾部斜杠。

我做错了什么?我尝试在 .htaccess 的最后一行中删除 .php 之后的斜杠,但没有这样做。

即使我添加“.html”作为我的 URL 后缀,它也不会被添加。这不在我的 .htaccess 中。

如果我尝试将 $route['news-and-events'] = "news"; 改为:$route['news-and-events/'] = "news"; 我会收到 404 错误

编辑:使用上述 .htaccess 时,我收到一个错误,即我使用了不允许的字符,即使我在配置文件中将“/”添加到允许的字符串。

【问题讨论】:

标签: codeigniter


【解决方案1】:

找到一个对我有用的,将我的 Blogger 帖子导入我的 Wordpress,然后我的反向链接不起作用,所以我只是用这个示例替换了我的 .htaccess,检查一下!

http://www.high-on-it.co.za/2011/02/removing-trailing-html-from-url/

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_URI} \.html$

RewriteRule ^(.*)\.html$ $1 [R=301,L]

RewriteRule ^index\.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    • 2012-01-12
    相关资源
    最近更新 更多