2013-10-24 86 views
1

我有一個網站,我們目前正在努力在以下目錄結構上:的.htaccess忽略的RewriteCond

root 
    - admin/ 
    - assets/ 
    - cache/ 
    - images/ 
    - .htaccess 
    - category.php 
    - image.php 
    - resize.php 

我想根據一些條件來重寫這些URL,並且已經實現了這個使用.htaccess 。出於某種原因,Apache似乎完全忽略了我添加的RewriteCond規則。下面是.htaccess文件的副本:

DirectoryIndex index.php category.php 
Options +FollowSymLinks 

RewriteEngine On 

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

# Image rewrites: 
RewriteRule ^([^/]+)/([0-9]+)/(.*)$ resize.php?function=resizeRatio&width=$2&src=images/$1/$3 [L] 
RewriteRule ^([^/]+)/([^/]+)([0-9]+)/(.*)$ resize.php?function=resizeRatio&width=$3&src=images/$1/$2/$4 [L] 
RewriteRule ^([^/]+)/([0-9]+)x([0-9]+)/(.*)$ resize.php?function=resizeCrop&width=$2&height=$3&src=images/$1/$4 [L] 
RewriteRule ^([^/]+)/([^/]+)([0-9]+)x([0-9]+)/(.*)$ resize.php?function=resizeCrop&width=$3&height=$4&src=images/$1/$2/$5 [L] 

# Category rewrites: 
RewriteRule ^([^/]+)/$ category.php?parent=$1 [L] 
RewriteRule ^([^/]+)/([^/]+)/$ category.php?parent=$1&child=$2 [L] 

RewriteRule ^([^/]+)/([^/]+).(.*)$ image.php?image=$2.$3&parent=$1 [L] 
RewriteRule ^([^/]+)/([^/]+)/([^/]+).(.*)$ image.php?image=$3.$4&parent=$1&child=$2 [L] 

當試圖訪問/admin/,我指向的category.php?category=admin/重寫後的頁面。

爲什麼Apache以這種方式行事,我該如何解決它?

+0

你知道RewriteConds只適用於直接跟隨它們的一個RewriteRule ...? – CBroe

回答

1

RewriteCond僅適用於非常接下來的RewriteRule

這個替換您RewriteCond線:

## If the request is for a valid directory 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
## If the request is for a valid file 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
## If the request is for a valid link 
RewriteCond %{REQUEST_FILENAME} -l 
## don't do anything 
RewriteRule^- [L] 

這將避免RewriteRule線休息一個有效的文件,目錄或鏈接。

+0

謝謝 - 這個作品完美。 – BenM

+0

不客氣,很高興它爲你解決。 – anubhava