对于我们目前正在开发的站点,我有以下目录结构:
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会以这种方式运行,我如何解决它?
发布于 2013-10-24 13:37:15
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行的其余部分。
https://stackoverflow.com/questions/19567460
复制相似问题