子文件夹中的Codeigniter URL尾部斜杠 [英] Codeigniter URL trailing slash breaks in subfolder

查看:67
本文介绍了子文件夹中的Codeigniter URL尾部斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a site based on Codeigniter, and when I'm in the default directory, www.removed.com... I have no problem. If I go here: www.removed.com/ It works just fine.

问题是当我导航到/ admin文件夹时(实际上只是应用程序/控制器) /admin/dashboard.php .....在路由配置中正确路由。

The problem is when I navigate to the /admin folder (which is really just application/controllers/admin/dashboard.php..... routed correctly in the routes config.

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

If I add a trailing slash to the end of anything under admin (like removed.com/admin/users/), the whole site breaks and the url tries inserting a url relative to my root: http://www.removed.com/home/accountName/public_html/skc/admin/users

有什么想法吗?

这是我的.htaccess

Here's my .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>

以下是路线配置(按要求):

Here's the routes config (as requested):

$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";


推荐答案

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

Change this condition to exclude the admin directory:

RewriteCond %{REQUEST_URI} ^ci.*

此外,您当前在此处使用黑名单方法,其中白名单将更为有效。因此,例如,如果您将所有图像,css和javascript文件都放在资产目录中,那么如果我们假设这是需要从外部访问的所有内容,则应执行以下操作:

Additionally, you're currently using a blacklist approach here, where a whitelist one would be more effective. So, if you for example have all your images, css and javascript files in an 'assets' directory, if we assume that this is everything that needs to be accessible from the outside world, you should do this:

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

这篇关于子文件夹中的Codeigniter URL尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆