htaccess mod在index.php之后重写和斜杠

时间:2016-11-04 15:21:36

标签: apache .htaccess mod-rewrite

我有以下.htaccess文件:

RewriteEngine on
RewriteBase   /
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

但也许是因为apache更新到版本2.4.23,这个停止了工作,浏览器返回消息file not found

我发现了那个网址

example.com/auth/login

index.php目录下搜索{document_root}/auth/login,而不是直接在{document_root}中搜索,因此无效。在%{DOCUMENT_ROOR}之前直接放置index.php变量不起作用,看起来像apache认为,文档根是从URL中获取的。

如何在index.php之后将整个路径重写为index.php?

EDIT 我正在使用fcgi,这是我的vhost文件:

<Directory "/Users/pogo/Development/www">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

<VirtualHost *:8080>
    ServerName dh
    ServerAlias *.dh

    VirtualDocumentRoot "/Users/pogo/Development/www/%-2.0.%-1/%0/www"
    DirectoryIndex index.html index.php
    RewriteEngine On

    <FilesMatch \.php$>
        SetHandler "proxy:unix:/usr/local/var/run/php5/php5-fpm.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>

1 个答案:

答案 0 :(得分:0)

您可以使用此规则:

AcceptPathInfo On
Options +FollowSymLinks
RewriteEngine on

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

请注意/index.php而不是./index.php