【问题标题】:Codeigniter URL trailing slash breaks in subfolder子文件夹中的 Codeigniter URL 尾部斜杠中断
【发布时间】:2012-11-13 01:14:46
【问题描述】:

我有一个基于 Codeigniter 的网站,当我在默认目录中时,www.removed.com... 我没有问题。如果我去这里:www.removed.com/ 它工作得很好。

问题是当我导航到 /admin 文件夹时(实际上只是 application/controllers/admin/dashboard.php .....在路由配置中正确路由。

如果我在 admin 下的任何内容(如 remove.com/admin/users/)的末尾添加一个斜杠,整个网站都会中断,并且 url 会尝试插入一个相对于我的根目录的 url:http://www.removed.com/home/accountName/public_html/skc/admin/users

有什么想法吗?

这是我的 .htaccess

<IfModule mod_rewrite.c>

RewriteEngine On

### Canonicalize codeigniter URLs

# If your default controller is something other than
# "welcome" you should probably change this
# RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
# RewriteRule ^(.*)/index/?$ $1 [L,R=301]

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
# RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
# RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]

# Enforce NO www
# RewriteCond %{HTTP_HOST} ^www\.removed\.com [NC]
# RewriteRule (.*) http://removed.com/$1 [R=301,L]

###

# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^ci.*
RewriteRule ^(.*)$ index.php/$1 [L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>


<IfModule !mod_rewrite.c>

# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php

</IfModule>

这是路线配置(根据要求):

$route['default_controller'] = "main";
$route['404_override'] = '';
$route['about'] = "main/about";
$route['news'] = "main/news";
$route['bikes'] = "main/bikes";
$route['gallery'] = "main/gallery";
$route['contact'] = "main/contact";

$route['admin'] = "admin/dashboard";
$route['admin/login'] = "admin/dashboard/login";
$route['admin/logout'] = "admin/dashboard/logout";
$route['admin/users/view-user'] = "admin/users/view_user";
$route['admin/users/view-user/:num'] = "admin/users/view_user";

【问题讨论】:

    标签: php .htaccess codeigniter


    【解决方案1】:

    更改此条件以排除管理目录:

    RewriteCond %{REQUEST_URI} ^ci.*
    

    此外,您目前在此处使用黑名单方法,其中白名单方法会更有效。因此,例如,如果您将所有图像、css 和 javascript 文件都放在“assets”目录中,如果我们假设这是需要从外部世界访问的所有内容,那么您应该这样做:

    RewriteCond %{REQUEST_URI} !^(index\.php|assets\/.*\..*)
    

    【讨论】:

      猜你喜欢
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多