mod_rewrite 配置问题

来源:3-9 初始化运行参数

JackWho

2017-04-11 16:56


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


写回答 关注

2回答

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

    apache需要加?

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

    JackWh...

    花了好几天时间配这个 ,最后还是有上面的方法hack了,但是这是pathinfo模式,而是 query模式。资料显示, 使用fcgi配置时,设置php 中一个 fix_pathinfo(记不清了,家里断网了,爪机模式)和 apache中一个对应的模式就能开启pathinfo, 设置后,并未生效。放弃了。phthinfo 和 mod_cgi 一样,不是主流了。

    2017-04-15 16:31:38

    共 1 条回复 >

  • 小猪爱红衣
    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
    这一句前面的#号去掉

    荒唐学子

    不行啊

    2019-02-16 17:14:02

    共 2 条回复 >

Restful API实战

PHP后端开发者如何迎上移动互联网发展热潮?

44010 学习 · 118 问题

查看课程

相似问题