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

别等时光非礼了梦想. 提交于 2019-12-07 08:05:58

问题


I have a working path on my Apache2 localhost (linux):

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

I want to become:

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

Now I have Rewrite mode enabled and tested.

I have placed my .htaccess file in my silex/web folder:

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

I still cannot see the clean url working.


回答1:


in your main folder try this: (for you this would be the silex folder)

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

and in the web folder:

<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>



回答2:


Try this code in your DOCUMENT_ROOT/.htaccess file:

Options -MultiViews
RewriteEngine On

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



回答3:


I found a code that works, but still only for /silex/web/hello/name. I want to make it work for /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>


来源:https://stackoverflow.com/questions/20591204/configure-htaccess-to-work-on-a-php-framework-silex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!