为什么这个RewriteRule与[R]一起使用而不与[QSA,L]一起使用?

时间:2014-02-13 06:43:50

标签: apache .htaccess mod-rewrite

我有一个非常简单的RewriteRule,但我无法弄清楚为什么它不想工作。也许它只是疲惫不堪的谈话,但似乎有些不可思议。

我想将看似http://mydomain.com/abc的网址重定向到http://mydomain.com/abc/index.php/xyz,但我不想更改网址。

这是我的.htaccess的全部内容:

RewriteEngine On 
RewriteBase /abc/

#redirect the homepage 
RewriteRule ^$  index.php/msj [QSA,L] 

当我这样做时,我得到“没有指定输入文件。”。如果我将[QSA,L]更改为[R]它可以工作,但它实际上重定向了URL。

我误解了什么?

编辑:$ _SERVER的输出

array(34) { [
"PATH"]=> string(29) "/bin:/usr/bin:/sbin:/usr/sbin" [
"RAILS_ENV"]=> string(10) "production" [
"FCGI_ROLE"]=> string(9) "RESPONDER" [
"UNIQUE_ID"]=> string(24) "UxDcvK3suH0AABgWvXUAAAAj" [
"SCRIPT_URL"]=> string(1) "/" [
"SCRIPT_URI"]=> string(22) "http://themspress.org/" [
"dsid"]=> string(8) "25793844" [
"ds_id_25793844"]=> string(0) "" [
"DH_USER"]=> string(13) "juancommander" [
"HTTP_HOST"]=> string(14) "themspress.org" [
"HTTP_CONNECTION"]=> string(5) "close" [
"HTTP_ACCEPT"]=> string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" [
"HTTP_USER_AGENT"]=> string(120) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36" [
"HTTP_ACCEPT_ENCODING"]=> string(17) "gzip,deflate,sdch" [
"HTTP_ACCEPT_LANGUAGE"]=> string(23) "en-US,en;q=0.8,es;q=0.6" [
"HTTP_COOKIE"]=> string(190) "OJSSID=Siy7xdofJurGtBcNUk1880; __utma=154159997.1153519437.1393351515.1393522373.1393598726.4; __utmc=154159997; __utmz=154159997.1393351515.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)" [
"SERVER_SIGNATURE"]=> string(0) "" [
"SERVER_SOFTWARE"]=> string(6) "Apache" [
"SERVER_NAME"]=> string(14) "themspress.org" [
"SERVER_ADDR"]=> string(15) "173.236.187.201" [
"SERVER_PORT"]=> string(2) "80" [
"REMOTE_ADDR"]=> string(14) "189.138.120.63" [
"DOCUMENT_ROOT"]=> string(51) "/home/juancommander/themspress.org/var/www/html/ojs" [
"SERVER_ADMIN"]=> string(24) "webmaster@themspress.org" [
"SCRIPT_FILENAME"]=> string(61) "/home/juancommander/themspress.org/var/www/html/ojs/index.php" [
"REMOTE_PORT"]=> string(5) "53719" [
"GATEWAY_INTERFACE"]=> string(7) "CGI/1.1" [
"SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" [
"REQUEST_METHOD"]=> string(3) "GET" [
"QUERY_STRING"]=> string(0) "" [
"REQUEST_URI"]=> string(1) "/" [
"SCRIPT_NAME"]=> string(10) "/index.php" [
"PHP_SELF"]=> string(10) "/index.php" [
"REQUEST_TIME"]=> int(1393614012) }

2 个答案:

答案 0 :(得分:1)

我在Dreamhost documentation找到了问题的根源。

似乎:

  

与Apache 2.2配对时的FastCGI版本似乎不喜欢   rewriterule index.php / $ 1。相反,它更喜欢index.php?$ 1但有些   CMS不喜欢这样。

我使用的CMS不喜欢这样。所以,撤消的评论是否正确使用?1美元是正确的,但由于我没有解释,我使用的CMS(开放日志系统)在一个?之后无法使用pathinfo的东西,那么它只是不起作用。

解决方案是从FastCGI更改为常规CGI。

答案 1 :(得分:0)

以下是发生的事情:

您发送http://mydomain.com/abc请求。 Apache的mod_rewrite将URL重写为http://mydomain.com/abc/index.php/msj,但保留了第一个URI。因此,当Apache要求php处理请求时,$_SERVER['REQUEST_URI']/abc/而不是/abc/index.php/msj,并且因为您的php应用程序(OJS)正在使用$_SERVER['REQUEST_URI']来处理请求,所以它赢了不知道应用于你的重写URL。将[QSA,L]替换为[R]时,apache会向您的浏览器发送Location标头。您的浏览器会发送另一个实际更改$_SERVER['REQUEST_URI']

的请求

不幸的是,我知道无法重写该部分。


<强>更新: 将它放在.htaccess文件中并检查它是否有效?

AcceptPathInfo On

<强>招

将其放入.htaccess文件中:

RewriteRule ^$  index.php?undone=/msj [QSA,L] 

编辑您的index.php文件并将其放在第一个开头:

    if(isset($_GET['undone'])){
        $_SERVER['REQUEST_URI'] = '/abc/index.php' . $_GET['undone'];
        unset($_GET['undone']);

    }