前段时间折腾zend framework ,然后访问目录默认并非网站的根目录,甚是郁闷;接下来symfony也是如此。假如我用的是虚拟主机,那么应用程序根目录肯定是入口,访问的时候不会再带一个web啥的跟到后面怪难看了。
默认的symfony的.htaccess文件如下:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c> RewriteEngine On
# uncomment the following line, if you are having trouble # getting no_script_name to work #RewriteBase /
# we skip all files with .something #RewriteCond %{REQUEST_URI} ..+$ #RewriteCond %{REQUEST_URI} !.html$ #RewriteRule .* - [L]
# we check if the .html version is here (caching) RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller RewriteRule ^(.*)$ index.php [QSA,L] </IfModule>
这个放到了web目录下,于是要么就域名绑定到web目录,要么就绑定到根目录,然后跟一个http://host/web/这样地址来访问。现在我们把这个修改成:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c> RewriteEngine On # we skip all files in /web RewriteCond %{REQUEST_URI} ^/web/ RewriteRule .* - [L] # we rewrite all other files with .something to /web RewriteCond %{REQUEST_URI} ..+$ RewriteCond %{REQUEST_URI} !.html$ RewriteRule ^(.*)$ /web/$1 [L] # !!! UNTESTED !!! ################################## # we check if the .html version is in /web (caching) RewriteRule ^$ /web/index.html [QSA] RewriteRule ^([^.]+)$ /web/$1.html [QSA] ##################################################### # no, so we redirect to our front web controller RewriteRule ^(.*)$ /web/index.php [QSA,L] </IfModule>
然后将其移动到网站根目录。直接访问index.php你会发现世界是多么的美好。睡觉!