问答详情
源自:3-9 初始化运行参数

mod_rewrite 配置问题


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L] // 之前在 index.php 后面追加问号,但是那样就不是 path_info 模式了 ?

.htaccess 中如下配置重写没有成功

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /web/restful/index.php/$1 [L]


http://img.mukewang.com/58ec99430001173e06510137.jpg

apache  LogLevel

LogLevel alert rewrite:trace3

// 运行 

tail -f error_log|fgrep '[rewrite:' 

// 捕获到的如下提示:
[vagrant@localhost logs]$ tail -f error_log|fgrep '[rewrite:'
[Tue Apr 11 08:51:27.852386 2017] [rewrite:trace1] [pid 14418:tid 140420398905088] mod_rewrite.c(477): [client 192.168.33.1:55502] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb624006918/initial/redir#1] [perdir /web/restful/] pass through /web/restful/index.php
[Tue Apr 11 08:51:33.041477 2017] [rewrite:trace3] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb62400aa10/initial] [perdir /web/restful/] strip per-dir prefix: /web/restful/article -> article
[Tue Apr 11 08:51:33.041513 2017] [rewrite:trace3] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb62400aa10/initial] [perdir /web/restful/] applying pattern '^(.*)$' to uri 'article'
[Tue Apr 11 08:51:33.041532 2017] [rewrite:trace2] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb62400aa10/initial] [perdir /web/restful/] rewrite 'article' -> '/web/restful/index.php/article'
[Tue Apr 11 08:51:33.041540 2017] [rewrite:trace2] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb62400aa10/initial] [perdir /web/restful/] strip document_root prefix: /web/restful/index.php/article -> /restful/index.php/article
[Tue Apr 11 08:51:33.041544 2017] [rewrite:trace1] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb62400aa10/initial] [perdir /web/restful/] internal redirect with /restful/index.php/article [INTERNAL REDIRECT]
[Tue Apr 11 08:51:33.041585 2017] [rewrite:trace3] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb6240119c8/initial/redir#1] [perdir /web/restful/] add path info postfix: /web/restful/index.php -> /web/restful/index.php/article
[Tue Apr 11 08:51:33.041592 2017] [rewrite:trace3] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb6240119c8/initial/redir#1] [perdir /web/restful/] strip per-dir prefix: /web/restful/index.php/article -> index.php/article
[Tue Apr 11 08:51:33.041597 2017] [rewrite:trace3] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb6240119c8/initial/redir#1] [perdir /web/restful/] applying pattern '^(.*)$' to uri 'index.php/article'
[Tue Apr 11 08:51:33.041608 2017] [rewrite:trace1] [pid 14419:tid 140420524795648] mod_rewrite.c(477): [client 192.168.33.1:55688] 192.168.33.1 - - [api.com/sid#25c1bb8][rid#7fb6240119c8/initial/redir#1] [perdir /web/restful/] pass through /web/restful/index.php


提问者:JackWho 2017-04-11 16:56

个回答

  • 慕圣0362214
    2017-04-12 11:02:24
    已采纳

    apache需要加?

    RewriteRule ^(.*)$ index.php?/$1 [L]

  • 小猪爱红衣
    2017-08-11 22:55:39

    在httpd.conf和httpd-vhosts.conf文件中搜索

    Options Indexes FollowSymLinks
    将AllowOverride None
    改为AllowOverride All

    然后将

    LoadModule rewrite_module modules/mod_rewrite.so
    这一句前面的#号去掉