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

Kan*_*ski 5 php apache .htaccess mod-rewrite silex

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

http://localhost/lab/silex/web/index.php/hello/name
Run Code Online (Sandbox Code Playgroud)

我想成为:

http://localhost/lab/silex/hello/name
Run Code Online (Sandbox Code Playgroud)

现在我启用并测试了重写模式.

我已将.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>
Run Code Online (Sandbox Code Playgroud)

我仍然看不到干净的网址工作.

Kri*_*eys 10

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

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

并在网络文件夹中:

<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>
Run Code Online (Sandbox Code Playgroud)


anu*_*ava 2

在您的文件中尝试以下代码DOCUMENT_ROOT/.htaccess

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_URI} !/lab/silex/web/index\.php/ [NC]
RewriteRule ^(.*)$ /lab/silex/web/index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)