2013-10-29 49 views
0

我以前有一些mod_rewrite錯誤,用一個簡單的;,子域上的Codeigniter鏈接樣式表和javascripts

這個問題已得到解決。 所以再次的結構,我有一個子域上的codeigniter應用程序。例如。 test.site.com

HTTPS-vhost.conf文件

NameVirtualHost *:80 

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

我位於我的應用程序,(htdocs中/測試/)

<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> 

所以的基部夾.htaccess文件,我現在可以加載CI_controllers,但是,我似乎無法鏈接任何樣式表或JavaScript文件。

這些文件都位於一個資產的文件夾,像這樣

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 

我需要創建特定的路線爲此呢?

+0

嘗試資產在你的URL大寫的A。 –

+0

對不起,這是我的錯字,一切都是小寫, – Lars

回答

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] 
0

我終於找到了一個答案我的道歉。

代碼點火器有點特殊,無論如何,這裏是國防部重寫我使用,並具有目前沒有問題。

# 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>