我有一个基于Codeigniter的网站,当我在默认目录中时,www.removed.com ...我没有问题。如果我去这里:www.removed.com/它运作得很好。
问题是当我导航到/ admin文件夹时(实际上只是application / controllers / admin / dashboard.php .....在路由配置中正确路由。
如果我在admin下的任何内容的末尾添加一个尾部斜杠(例如removed.com/admin/users/),则整个站点会中断,并且url会尝试插入相对于我的root的URL:http://www.removed.com/home/accountName/public_html/skc/admin/users < / p>
有什么想法吗?
这是我的.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";
答案 0 :(得分:1)
更改此条件以排除管理目录:
RewriteCond %{REQUEST_URI} ^ci.*
此外,您目前正在使用黑名单方法,其中白名单方法会更有效。所以,如果您将所有图像,css和javascript文件放在'assets'目录中,如果我们假设这是需要从外部世界访问的所有内容,那么您应该这样做:
RewriteCond %{REQUEST_URI} !^(index\.php|assets\/.*\..*)