開啟 Rewrite模組
a2enmod rewrite
確認
apache2ctl -M | grep rewrite
編輯 /etc/apache2/sites-enabled/000-default.conf 加入
<Directory "/var/www/html">
AllowOverride All
</Directory>
編輯 /var/www/html/.htaccess 加入
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
或直接加在 </VirtualHost>
RewriteEngine On
# RewriteCond %{LA-U:REQUEST_FILENAME} -d
# RewriteRule ^ - [L]
# RewriteCond %{LA-U:REQUEST_FILENAME} -f
# RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</VirtualHost>
Apache 2.2.16 版本中首次引入
FallbackResource /index.phpFallbackResource 接受的路徑必須是 Web 網址路徑(URL Path / DocumentRoot 相對路徑),而不是伺服器的檔案系統絕對路徑(Absolute File Path)。
沒有留言:
張貼留言