我尝试了一切,我启用了重写模块,搞乱了apache配置,但我的服务器仍然不会自动添加.php扩展名。它只是一直显示404错误。
顺便说一下,我在虚拟主机上进行了此设置。
这是我的Apache配置:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port th$
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/ce
ServerName computingessentials.tk
ServerAlias www.computingessentials.tk
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/ce/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
这是我的htaccess
RewriteEngine on
RewriteRule ^([0-9a-zA-Z-]+)$ $1.php [NC,L]
RewriteRule ^([0-9a-zA-Z-]+)/$ $1.php [NC,L]
RewriteRule ^videos/([0-9a-zA-Z-]+)$ videos.php?var=$1 [NC,L]
RewriteRule ^article/([0-9a-zA-Z-]+)$ article.php?var=$1 [NC,L]
RewriteRule ^video/([0-9a-zA-Z-]+)$ video.php?var=$1 [NC,L]
例如,有一个名为series.php
的网页,应该替换为/series
,但当我转到/series
时,会显示找不到文件。
您将无法访问服务器,因为此时我已设置主机文件以将我重定向到IP。 标记为:入门,Apache,DigitalOcean文章,DNS,PHP,系统工具,Ubuntu
答案 0 :(得分:0)
首先,在Ubuntu 14.04(和Apache 2.4)中,默认的DocumentRoot已从/var/www
更改为/var/www/html
您的配置文件显示<Directory /var/www/ce/>
尝试将其更改为默认
答案 1 :(得分:0)
以这种方式尝试您的代码,并检查您的文件是否存在。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([0-9a-zA-Z-]+)/?$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^videos/([0-9a-zA-Z-]+)$ videos.php?var=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9a-zA-Z-]+)$ article.php?var=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^video/([0-9a-zA-Z-]+)$ video.php?var=$1 [NC,L]