0

我正在使用 codeigniter 构建我的网站,这里有一个给我带来麻烦的路由规则示例:

$route['updategamepage/(:num)'] = 'maincontroller/main/updategamepage/$1';

那么规则的格式/结构有什么问题吗?这是使用该规则的示例 url:

http://www.mydomain.com/ci_website/updategamepage/6

并且当该页面被加载时,css/js 不会与页面一起加载......知道出了什么问题吗?

4

2 回答 2

1

你的路由规则应该只适用于通过 CodeIgniter 的 index.php 文件路由的东西。该路由由应用程序的 .htaccess 文件决定。当您不希望它时,您的 htaccess 可能会将请求重定向到您的 .css 文件到 CodeIgniter。

最终,您可能会检查您的 Web 服务器日志,包括可能启用 mod_rewrite 日志记录,以查看实际发生的情况。

这是我用于 CodeIgniter 应用程序的示例 .htaccess:

(请注意,您必须更改顶部附近的 RewriteBase 指令)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/

#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} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule> 
于 2012-07-11T23:43:12.437 回答
0

.htaccess这是我在项目中经常使用的一个简短片段,它更容易理解。

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|shared|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]

它的作用是将每个不包含index.php, assets, shared,uploadsrobots.txtURL 重定向到您的公共文件夹的 URL 之后到您的index.php文件,允许您将$config['index_page']值设置为 '',这将使您的 URL 更令人赏心悦目和搜索引擎。没有这个,你就有了类似的 URL http://www.mysite.com/index.php/pages/about,有了它,你将拥有http://www.mysite.com/pages/about.

我个人将我的JSCSS文件保存在assets文件夹中,但如果您想将它们保存在根文件夹中,只需将它们的文件夹名称添加到.htaccess我提供的文件的第二行,并用|符号分隔

RewriteCond $1 !^(index\.php|js|css|shared|uploads|robots\.txt)

正如我在几分钟前对您的另一个问题的回答中所建议的那样,您最好删除您的$config['base_url']价值内容并让 CodeIgniter 为您完成这项工作 - 他做得非常好。

于 2012-07-12T02:58:03.940 回答