将.htaccess配置为使用PHP框架(Silex)


Configure .htaccess to work on a PHP Framework (Silex)

我在Apache2 localhost(linux)上有一个工作路径:

http://localhost/lab/silex/web/index.php/hello/name

我想成为:

http://localhost/lab/silex/hello/name

现在我已经启用并测试了"重写"模式。

我已将.htaccess文件放在silex/web文件夹中:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteBase /web/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>

我仍然看不到干净的url工作。

在您的主文件夹中尝试这个:(对您来说,这将是silex文件夹)

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

和在web文件夹中:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    RewriteCond %{THE_REQUEST} ^(GET|HEAD)' /web/
RewriteRule ^(.*)$ /$1 [L,R=301]
</IfModule>

DOCUMENT_ROOT/.htaccess文件中尝试此代码:

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !/lab/silex/web/index'.php/ [NC]
RewriteRule ^(.*)$ /lab/silex/web/index.php/$1 [L]

我找到了一个有效的代码,但仍然只适用于/silex/web/hello/name。我想让它为/silex/hello/name 工作

<IfModule mod_rewrite.c>
    Options -MultiViews -Indexes
    RewriteEngine On
    #RewriteBase /path/to/app
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</IfModule>