在網上看了很多帖子,發現說Ubuntu的很少,那我就來說兩句
開啓rewrite
其實這個不是必要選項,只不過在URL中有index.php這樣的字眼實在是很low,所以還是開了吧
打開方式:
# a2enmod rewrite
只有這麼一行命令,網上那些linux博客說的httpd.conf去掉#Load……什麼的前面的#,對Ubuntu不適用,上面一行就夠了
如果報錯,仔細看看,最後如果有
Enabling module rewrite.
就不要管他了,直接
# service apache2 restart
修改配置文件
網上這個倒是多的是,就是配置文件改哪個的問題
我來說說我改了什麼吧,也許改的有多餘,但是working了
首先是/etc/apache2/apache2.conf
用vim /etc/apache2/apache2.conf打開,然後/override\c找到下面的段落
<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/youge/blog/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
通常一個域名下面是一個項目,所以,哪個文件路徑就從/var/www改成了具體的,index.php之前的那部分路徑,但是還要注意的是,有兩個AllowOverride後面的改成了All
:wq保存退出
然後是/etc/apache2/sites-enabled/000-default.conf
vim /etc/apache2/sites-enabled/000-default.conf
找到serverName 和 documentRoot
ServerName www.gaigshi.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/youge/public
:wq保存退出
我用的是php laravel框架,如何優雅連接(laravel文檔)
這樣就可以啦!
別的框架也一定有重定向的方式,大家自行百度吧~