0

我以前遇到过一些 mod_rewrite 错误,用一个简单的 ;,

好吧,这已经解决了。再说一遍结构,我在子域上有一个 codeigniter 应用程序。例如。test.site.com

https-vhost.conf 文件

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/test"
    ServerName test.localhost.com
</VirtualHost>

我的 .htaccess 文件位于我的应用程序的基本文件夹中,(htdocs/test/)

<IfModule mod_rewrite.c>

    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On

    RewriteBase /

    RewriteCond %{HTTP_HOST} !www.localhost.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/$
    RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).localhost.com [NC]
    RewriteRule (.*) /index.php/ [P]

    RewriteCond $1 !^(index\.php|images|robots\.text|css|js)
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

所以,我现在可以加载 CI_controllers,但是,我似乎无法链接任何样式表或 javascript 文件。

这些文件位于 Assets 文件夹中,如下所示

htdocs
  |-test
  |  |-application
  |  |-assets
  |  |  |-css
  |  |  |  |-style.css
  |  |  |-js
  |  |  |  |-jquery.js

即使有完整的站点链接,我似乎也无法加载这些文件,

Request URL: http://test.localhost.com/assets/css/style.css
Request Method: GET
Status Code: 404 Not Found

我是否也需要为此创建特定的路由?

4

2 回答 2

0

我最终找到了答案,我很抱歉。

Code Igniter 有点特别,无论如何,这是我正在使用的 mod 重写,现在没有问题。

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    # mod_rewrite rules
    RewriteEngine on

    # The RewriteBase of the system (if you are using this sytem in a sub-folder).
    # RewriteBase /

    # This will make the site only accessible without the "www." 
    # (which will keep the subdomain-sensive config file happy)
    # If you want the site to be accessed WITH the "www." 
    # comment-out the following two lines.
    RewriteCond %{HTTP_HOST} ^www\.localhost\.com$ [NC]
    RewriteRule ^(.*)$ http://localhost.com/$1 [L,R=301]

    # If a controler can't be found - then issue a 404 error from PHP
    # Error messages (via the "error" plugin)
    # ErrorDocument 403 /index.php/403/
    # ErrorDocument 404 /index.php/404/
    # ErrorDocument 500 /index.php/500/

    # Deny any people (or bots) from the following sites: (to stop spam comments)
    # RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]
    # RewriteCond %{HTTP_REFERER} porn\.com
    # RewriteRule .* - [F]
    # Note: if you are having trouble from a certain URL just 
    # add it above to forbide all visitors from that site.

    # You can also uncomment this if you know the IP:
    # Deny from 192.168.1.1

    # If the file is NOT the index.php file
    # RewriteCond %{REQUEST_FILENAME} !index.php
    # Hide all PHP files so none can be accessed by HTTP
    # RewriteRule (.*)\.php$ index.php/$1

    # If the file/dir is NOT real go to index
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]

</IfModule>

# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule> 
于 2013-10-30T00:05:29.857 回答
0

尝试排除资产目录或以 css/js 结尾的任何内容:

RewriteCond $1 !^(index\.php|images|robots\.text|css|js|assets)
RewriteRule ^(.*)$ /index.php/$1 [L]

或者:

RewriteCond $1 !\.(css|js)$ [NC]
RewriteCond $1 !^(index\.php|images|robots\.text|css|js)
RewriteRule ^(.*)$ /index.php/$1 [L]
于 2013-10-29T08:15:38.117 回答