我正在尝试让 mod 重写起作用,目前我得到 404。
规则如下:
Options +FollowSymlinks
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/portfolio/([\w-]+)$ `index.php?portfolio=$1`
当我输入example.com/portfolio/derp
时,得到的是 404 index.php?portfolio=derp
。
这是重写日志文件:
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] applying pattern '^' to uri 'portfolio/derp'
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (4) [perdir /var/www/html/] RewriteCond: input='off' pattern='!=on' => matched
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (4) [perdir /var/www/html/] RewriteCond: input='www.example.com' pattern='^www\.(.+)$' [NC] => matched
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (2) [perdir /var/www/html/] rewrite 'portfolio/derp' -> 'http://example.com/portfolio/derp'
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (2) [perdir /var/www/html/] explicitly forcing redirect with http://example.com/portfolio/derp
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (1) [perdir /var/www/html/] escaping http://example.com/portfolio/derp for redirect
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (1) [perdir /var/www/html/] redirect to http://example.com/portfolio/derp [REDIRECT/301]
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] applying pattern '^' to uri 'portfolio/derp'
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (4) [perdir /var/www/html/] RewriteCond: input='off' pattern='!=on' => matched
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (4) [perdir /var/www/html/] RewriteCond: input='example.com' pattern='^www\.(.+)$' [NC] => not-matched
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] applying pattern '^/portfolio/([\w-]+)$' to uri 'portfolio/derp'
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] applying pattern '(^|/)\.' to uri 'portfolio/derp'
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/404.html -> 404.html
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^' to uri '404.html'
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (4) [perdir /var/www/html/] RewriteCond: input='off' pattern='!=on' => matched
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (4) [perdir /var/www/html/] RewriteCond: input='example.com' pattern='^www\.(.+)$' [NC] => not-matched
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/404.html -> 404.html
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^/portfolio/([\w-]+)$' to uri '404.html'
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/404.html -> 404.html
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '(^|/)\.' to uri '404.html'
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (1) [perdir /var/www/html/] pass through /var/www/html/404.html
希望你能理解。就我而言,它可以用日语写出来。
好的,我已经将其精简.htaccess
为以下内容:
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^portfolio/([\w-]+)$ index.php?portfolio=$1
删除前导斜杠,这会加载 index.php,但当它们位于根目录中时,它会在 /portfolio 中查找所有链接的内容图片、css 样式表等。
以下是重写的日志:
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/derp'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (4) [perdir /var/www/html/] RewriteCond: input='/var/www/html/portfolio' pattern='!-d' => matched
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (4) [perdir /var/www/html/] RewriteCond: input='/var/www/html/portfolio' pattern='!-f' => matched
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (2) [perdir /var/www/html/] rewrite 'portfolio/derp' -> 'index.php?portfolio=derp'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) split uri=index.php?portfolio=derp -> uri=index.php, args=portfolio=derp
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add per-dir prefix: index.php -> /var/www/html/index.php
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (2) [perdir /var/www/html/] strip document_root prefix: /var/www/html/index.php -> /index.php
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] internal redirect with /index.php [INTERNAL REDIRECT]
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#8656878/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/index.php -> index.php
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#8656878/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'index.php'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#8656878/initial/redir#1] (1) [perdir /var/www/html/] pass through /var/www/html/index.php
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/indexstyles.css
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/indexstyles.css -> portfolio/indexstyles.css
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/indexstyles.css'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86518a8/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/jquery-1.7.1.min.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86518a8/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/jquery-1.7.1.min.js -> portfolio/jquery-1.7.1.min.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86518a8/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/jquery-1.7.1.min.js'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86518a8/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/scripts/all.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/scripts/all.js -> portfolio/scripts/all.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/scripts/all.js'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/scripts/jquery.history.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/scripts/jquery.history.js -> portfolio/scripts/jquery.history.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/scripts/jquery.history.js'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/projectimg/leoimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/projectimg/leoimg.png -> portfolio/img/projectimg/leoimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/projectimg/leoimg.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/projectimg/regformimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/projectimg/regformimg.png -> portfolio/img/projectimg/regformimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/projectimg/regformimg.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/projectimg/fileupimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/projectimg/fileupimg.png -> portfolio/img/projectimg/fileupimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/projectimg/fileupimg.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/projectimg/carimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/projectimg/carimg.png -> portfolio/img/projectimg/carimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/projectimg/carimg.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/chromeicon.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/chromeicon.png -> portfolio/img/chromeicon.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/chromeicon.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
答案1
从规则的开头删除/
;您在每个目录上下文(文件.htaccess
或<Directory>
块)中获得它,因此没有前导斜杠。
RewriteRule ^portfolio/([\w-]+)$ index.php?portfolio=$1
修复此问题后,您可能还会遇到其他规则的一些问题 - 尝试一下,但如果仍然有问题,您能提供其余的配置吗?