2016-03-24 45 views
1

我有一個htaccess的重定向我的鏈接:重寫模塊對jQuery的

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

的問題是,這個的.htaccess不允許包含在我的網站的jquery,即使我有這個在<head>

<script src="<?php echo WEBROOT;?>views/js/jquery.js"></script> 

我已經嘗試過:

RewriteRule ^(views/js/)($|/) - [L] 

以除外其中的jquery.js所在的文件夾。我也試過了:

RewriteCond %{REQUEST_URI} !^/js/?$ 

但是什麼都不允許jquery !!

有什麼解決方法嗎?

+1

'的RewriteCond% {REQUEST_FILENAME}!-f'已經不重定向現有文件,不需要爲jquery添加特殊規則。你的'src =「wrongpath」'是錯誤的 –

+0

謝謝你的回答,但我確定我的src =「NotAWrongPath」因爲我可以通過ctrl + u訪問該文件,我甚至試圖用' src =「ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js」'但仍不起作用!順便說一句,如果我禁用.htaccess jquery工作正常! –

+0

嘗試添加''到你的網頁的頭部。 – starkeen

回答

0

這是我的.htaccess:

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

這是我的jQuery的包括:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> 

或者

<script type="text/javascript" src="<?php echo WEBROOT;?>js/jquery.js"></script> 

這是我的index.php頁面:

<?php 
define('ROOT',str_replace('index.php','' ,$_SERVER['SCRIPT_FILENAME'])); 
define('WEBROOT',str_replace('index.php','' ,$_SERVER['SCRIPT_NAME'])); 

require ('core/database.php'); 
require ('core/controller.php'); 
require ('core/model.php'); 
require ('core/view.php'); 


$url = isset($_GET['url']) ? $_GET['url'] : null; 

if (empty($url)) { 
    require ('controllers/home.php'); 
    $controller = new home(); 
    return FALSE; 
} 

$params = explode('/', $url); 
$file = 'controllers/'. $params[0] .'.php'; 
if(is_file($file)){ 
    require $file; 
    $controller = new $params[0](); 
    $model = $controller->loadModel($params[0]); 

    if(isset($params[1])){ 
     if (method_exists($params[0], $params[1])) { 
      $controller->{$params[1]}(); 
     } 
     else { 
      echo '<h1>Method '.$params[1].' of Controller '.$params[0].' Not Found</h1>'; 
     } 
    } 
} else { 
    /* can't find controller*/ 
    echo '<h1>Controller Not Found</h1>'; 
} 

?> 

所以jQuery是現在才主頁上的工作,我的意思是像網頁:

localhost/myProject/controller1/method1它不工作

很抱歉,如果它是一個很長的帖子,但請檢查一下你們