2011-07-20 12 views
5

मैंने अभी अपने कोडिनेटर एप्लिकेशन में एक htaccess फ़ाइल जोड़ा है जो यूआरएल से "index.php" को हटा देता है। यूआरएल ठीक काम कर रहा है, लेकिन अब सीएसएस लिंक काम नहीं कर रहे हैं, भले ही संदर्भ पूर्ण हैं (यानी "http: // ...") छवियों के साथ-साथ अन्य सभी लिंक पूरी तरह से ठीक काम करते हैं, लेकिन सीएसएस फाइलें जीती हैं लोड नहीं यह HTAccess फ़ाइल है।कोडइग्निटर HTAccess सीएसएस फाइलों को लोड नहीं करता

RewriteEngine on RewriteCond $1 !^(main.php|images|robots.txt) RewriteRule ^(.*)$ main.php/$1 [L]

और हाँ अभी तो मैं अपना इंडेक्स फ़ाइल क्योंकि मैं एक ही सीआई स्थापना पर दो अलग-अलग आवेदन पत्र का उपयोग किया जाएगा main.php है। किसी भी मदद के लिए धन्यवाद।

उत्तर

9

आप निम्न प्रयास करना चाह सकते:

# 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 ^(.*)$ main.php/$1 [L] 

यह बिना आपके द्वारा बनाए गए वेब रूट (शैलियों, छवियों, स्क्रिप्ट) में जो कुछ भी फ़ोल्डरों आप चाहते हैं की अनुमति देगा उन्हें htaccess फ़ाइल में घोषित करें।

+0

robots.txt और साइटमैप को न भूलें। –

+0

यह इस कोड के साथ अप्रासंगिक है, यह जांच करेगा कि फ़ाइल फाइल सिस्टम में मान्य है या नहीं, और यदि अनुप्रयोग मौजूद नहीं है तो अनुप्रयोग main.php फ़ाइल पर रीडायरेक्ट करें। यह robots.txt, साइटमैप के लिए खुशी से काम करेगा - बहुत कुछ भी। – simnom

+0

क्षमा करें बाहर नहीं देखा था। समाधान हल करें। –

2

अपने htaccess फ़ाइल एक पंक्ति :)

RewriteEngine on 
RewriteCond $1 !^(main\.php|images|robots\.txt|styles) 
RewriteRule ^(.*)$ /main.php/$1 [L] 

आप RewriteCond पंक्ति में अपनी शैलियों निर्देशिका डाल सकता है याद आ रही है। मैंने उदाहरण के लिए शैलियों को जोड़ा।

अधिक जानकारी here

+0

इसके अलावा के रूप में base_url फ़ंक्शन का उपयोग करें, आपको उस यूआरएल को जोड़ना होगा जिसे आप यहां एक्सेस करना चाहते हैं। अन्यथा उन्हें main.php/$ url पृष्ठ पर रीडायरेक्ट किया जाएगा (जो तब मौजूद है, मौजूद नहीं है)। –

1

आप पर देख सकते हैं। Htaccess फ़ाइल जो मैं अब उपयोग कर रहा हूं।

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt|css|design|img|js) 
RewriteRule ^(.*)$ /a-cat/index.php/$1 [L] 
</IfModule> 

निर्देशिका संरचना इस तरह है:

enter image description here

सीएसएस फ़ाइल इस तरह से इस्तेमाल किया जा सकता है:

<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/main.css" /> 
2

मैं इस का उपयोग करें। अच्छी तरह से टिप्पणी की है, और स्पष्ट रूप से मेरे द्वारा लिखा नहीं है।

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

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

इस समस्या का सरल जवाब है: नीचे और अपने सीएसएस के पथ पर दिया CodeIgniter से .htaccess कोड का उपयोग करें के रूप में, जे एस और चित्र दिखाए

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase # The path to your project/official/hrm/ 

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

<link rel="stylesheet" href="<?php echo base_url(); ?>the rest of path to yourfile"> 
संबंधित मुद्दे