可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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>