php - mod_rewrite来消除 index.php

  显示原文与译文双语对照的内容
119 5

我花了几天时间来重写规则,以便在我的专用服务器上安装OJS程序( http://pkp.sfu.ca/?q=ojs ) 。 我的服务器安装了 Apache 2.4.2和 PHP 5. 它有另外两个PHP程序( 一个工作板和一个论坛) 和重写规则来删除 index.php 工作良好。 然而,对于OJS程序,我尝试了在网上找到的所有规则,无法重写。 问题始终是重定向循环。 下面是我尝试的规则 htaccess ( 注释出的行单独或者与其他行进行了测试):


Options +FollowSymLinks
RewriteEngine On
#RewriteBase/

# Use this set of 3 lines for each of your journals
#RewriteCond %{SERVER_NAME} ^www.mysite.org
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
#RewriteCond %{REQUEST_URI}!=/index.php
#RewriteCond %{REQUEST_URI}!^/index.php/.*
#RewriteRule ^(.*)$ index.php/$1" [L,NS] 
RewriteRule ^(.*)$ index.php/$1 [QSA,L] 

# Use this set of 3 lines to allow access to the site level
#RewriteCond %{SERVER_NAME} ^www.mysite.org
#RewriteCond %{REQUEST_FILENAME}!-d
#RewriteCond %{REQUEST_FILENAME}!-f
#RewriteRule ^(.*)$"/index.php/index/$1" [QSA,L]


#RewriteCond %{SERVER_NAME} ^www.mysite.org
#RewriteCond %{REQUEST_FILENAME}!-d
#RewriteCond %{REQUEST_FILENAME}!-f
#RewriteCond %{THE_REQUEST}!^[A-Z]{3,9}/([^/]+/)*index.php HTTP/
#RewriteCond %{REQUEST_URI} index.php
#RewriteRule ^(.*)$/index.php/$1 [QSA,L]
#RewriteCond %{REQUEST_URI}!=/index.php
#RewriteRule ^(.*)$ index.php/$1" [L,PT] 

下面是Apache错误日志


[Sat Sep 21 00:08:53.413993 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a725b0/initial] [perdir/home/mysite/public_html/] strip per-dir prefix:/home/mysite/public_html/journal -> journal
[Sat Sep 21 00:08:53.414013 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a725b0/initial] [perdir/home/mysite/public_html/] applying pattern '^(.*)$' to uri 'journal'
[Sat Sep 21 00:08:53.414039 2013] [rewrite:trace2] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a725b0/initial] [perdir/home/mysite/public_html/] rewrite 'journal' -> '/index.php/journal'
[Sat Sep 21 00:08:53.414051 2013] [rewrite:trace2] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a725b0/initial] [perdir/home/mysite/public_html/] trying to replace prefix/home/mysite/public_html/with/
[Sat Sep 21 00:08:53.414061 2013] [rewrite:trace1] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a725b0/initial] [perdir/home/mysite/public_html/] internal redirect with/index.php/journal [INTERNAL REDIRECT]
[Sat Sep 21 00:08:53.414109 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a740c8/initial/redir#1] [perdir/home/mysite/public_html/] add path info postfix:/home/mysite/public_html/index.php ->/home/mysite/public_html/index.php/journal
[Sat Sep 21 00:08:53.414122 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a740c8/initial/redir#1] [perdir/home/mysite/public_html/] strip per-dir prefix:/home/mysite/public_html/index.php/journal -> index.php/journal
[Sat Sep 21 00:08:53.414132 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a740c8/initial/redir#1] [perdir/home/mysite/public_html/] applying pattern '^(.*)$' to uri 'index.php/journal'
[Sat Sep 21 00:08:53.414151 2013] [rewrite:trace1] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a740c8/initial/redir#1] [perdir/home/mysite/public_html/] pass through/home/mysite/public_html/index.php
[Sat Sep 21 00:08:53.414206 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a80650/subreq] [perdir/home/mysite/public_html/] strip per-dir prefix:/home/mysite/public_html/journal -> journal
[Sat Sep 21 00:08:53.414230 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a80650/subreq] [perdir/home/mysite/public_html/] applying pattern '^(.*)$' to uri 'journal'
[Sat Sep 21 00:08:53.414249 2013] [rewrite:trace2] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a80650/subreq] [perdir/home/mysite/public_html/] rewrite 'journal' -> '/index.php/journal'
[Sat Sep 21 00:08:53.414260 2013] [rewrite:trace2] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a80650/subreq] [perdir/home/mysite/public_html/] trying to replace prefix/home/mysite/public_html/with/
[Sat Sep 21 00:08:53.414267 2013] [rewrite:trace1] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a80650/subreq] [perdir/home/mysite/public_html/] internal redirect with/index.php/journal [INTERNAL REDIRECT]
[Sat Sep 21 00:08:53.492920 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a80650/initial] [perdir/home/mysite/public_html/] strip per-dir prefix:/home/mysite/public_html/journal -> journal
[Sat Sep 21 00:08:53.492937 2013] [rewrite:trace3] [pid 22466] mod_rewrite.c(468): [www.mysite.com/sid#9a22888][rid#9a80650/initial] [perdir/home/mysite/public_html/] applying pattern '^(.*)$' to uri 'journal'

谁能告诉我如何让它工作,以及问题是否与mod_rewrite或者OJS程序一起出现?

感谢你的时间提前。

编辑:现在我尝试了以下仍然存在同样问题的问题。


DirectoryIndex index.php
# Turn mod_rewrite on
RewriteEngine On
RewriteBase/
# internally add index.php to all URIs
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d 
RewriteRule!^index.php index.php%{REQUEST_URI} [L,NC] 

时间: 原作者:

145 1

以下是可以用来从url中的任意位置删除 /index.php的代码:


DirectoryIndex index.php

# Turn mod_rewrite on
RewriteEngine On
RewriteBase/

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s(.*?/+)index.php(?:/(.*))?[s?] [NC]
RewriteRule ^ %1%2 [L,R]

# internally add index.php to all URIs
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d 
RewriteRule!^index.php index.php%{REQUEST_URI} [L,NC]

原作者:
...