apache的重写模块在vps服务器LAMP上不起作用(ubuntu 18.04)
我所做的:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
2) 启用当前虚拟主机:
sudo a2ensite example.com.conf
3) 禁用默认设置:
sudo a2dissite 000-default.conf
4) 激活Mod_重写
sudo a2enmod rewrite
5) 在/etc/apache2/apache2.conf中添加配置
<Directory /var/www/example.com/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
sudo systemctl restart apache2
主页可以正常工作,但如果我单击一个链接,例如.com/product-page-1,它会显示:
The requested URL /product-page-1 was not found on this server.
我做错了什么???
使现代化
.htaccess文件
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# some redirects
Redirect 301 /create-account.html /register
...
</IfModule>
更新2
我在htaccess中有25-30个301重定向,如果我不删除它们,服务器就会失败
The server encountered an internal error or misconfiguration and was unable to complete your request.
如果我查看appache2的错误日志,我会看到:
/var/www/example.com/html/.htaccess: Invalid command 'Register', perhaps misspelled or defined by a module not included in the server configuration
什么模块需要apache 301重定向才能工作???