我正在使用Silex"微框架"来实现应用程序的路由目的。我目前卡住了如何重写url与。htaccess.
标准Silex url: localhost/myapp/web/index.php/hello/name
我想让它看起来像:localhost/myapp/hello/name
使用以下.htaccess代码,我可以省略/index.php/
部分。但是我仍然必须使用/web/
部分。
RewriteEngine On
RewriteCond %{THE_REQUEST} /myapp/web/index.php/
RewriteRule ^/myapp/web/index.php/(.*) /myapp/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !/myapp/web/index.php/
RewriteRule ^(.*)$ /myapp/web/index.php/$1 [L]
有什么建议吗?谢谢!
我现在遇到了同样的问题,解决方案是将。htaccess内容更改为:
FallbackResource /index.php
在你的例子中是
FallbackResource /web/index.php
From: http://silex.sensiolabs.org/doc/web_servers.html
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
右边是将DocumentRoot
设置为/path/to/your/app/web
。
类似这样的代码应该可以达到这个效果:
RewriteEngine On
RewriteBase /
RewriteRule ^myapp/web/index.php/ /myapp/ [R=301,L]
RewriteRule ^myapp/ /myapp/web/index.php/ [L]
我有一个类似的问题,用下面的
解决<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)? index.php/$1 [QSA,L]
RewriteRule ^/?$ /web/ [R=301]
</IfModule>