【问题标题】:.htaccess stop internal redirect.htaccess 停止内部重定向
【发布时间】:2012-06-04 09:08:41
【问题描述】:

首先,这是我的目录结构

/localhost/p/
  .htaccess
/localhost/p/inc/
  style.css

我在/localhost/p/.htaccess上有这个sn-p

Options -MultiViews +FollowSymLinks 
RewriteEngine On
RewriteBase /p/

RewriteCond %{REQUEST_FILENAME} ^(.+)/([^/]+)$
RewriteCond %1/inc/%2 -f
RewriteRule ([^/]+)$ inc/$1 [L]

RewriteRule ^(.+)$ index.php [QSA,L]

它不允许我访问localhost/p/style.css 的文件,但它会让我访问 index.php

这是日志

[perdir D:/p/] strip per-dir prefix: D:/p/style.css -> style.css
[perdir D:/p/] applying pattern '([^/]+)$' to uri 'style.css'
[perdir D:/p/] RewriteCond: input='D:/p/style.css' pattern='^(.+)/([^/]+)$' => matched
[perdir D:/p/] RewriteCond: input='D:/p/inc/style.css' pattern='-f' => matched
[perdir D:/p/] rewrite 'style.css' -> 'inc/style.css'
[perdir D:/p/] add per-dir prefix: inc/style.css -> D:/p/inc/style.css

// I don't know how to stop the .htaccess here, and just get the file
// instead go with [INTERNAL REDIRECT]

[perdir D:/p/] trying to replace prefix D:/p/ with /p/
strip matching prefix: D:/p/inc/style.css -> inc/style.css
add subst prefix: inc/style.css -> /p/inc/style.css
[perdir D:/p/] internal redirect with /p/inc/style.css [INTERNAL REDIRECT]
[perdir D:/p/] strip per-dir prefix: D:/p/inc/style.css -> inc/style.css
[perdir D:/p/] applying pattern '([^/]+)$' to uri 'inc/style.css'
[perdir D:/p/] RewriteCond: input='D:/p/inc/style.css' pattern='^(.+)/([^/]+)$' => matched
[perdir D:/p/] RewriteCond: input='D:/p/inc/inc/style.css' pattern='-f' => not-matched

// Of course it will never match, it should be D:/p/inc/style.css

...
...
...

谢谢,

【问题讨论】:

标签: .htaccess mod-rewrite redirect


【解决方案1】:

使用此 RewriteCond 允许不超过 1 个内部重定向:

## prevent looping from internal redirects
RewriteCond %{ENV:REDIRECT_STATUS} !200

【讨论】:

  • 顺便说一句,我应该把那行放在哪里?错误的顺序会返回意想不到的结果对吗?谢谢
  • 放在这一行之前:RewriteRule ([^/]+)$ inc/$1 [L]
猜你喜欢
  • 2012-09-19
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多