为什么我的.htaccess不能在这个VPS上工作?

我在/public_html/.htaccess有以下.htaccess文件:

 # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress 

这里是我的public_html /目录在Ubuntu 14服务器的权限Wordpress 4.1 Apache 2.4我有相同的.htaccess文件相同的Wordpress网站附近,我不明白为什么我在我的Wordpress页面上收到404错误 – 注意我我能够看到我的网站主页,但每当一个链接被点击一个404错误生成,上次发生这种情况,我发现一个.htaccess错字,这一次我不知道..

我的错误和访问日志具有相同的权限,我看到访问日志写入我访问的网站,但在错误日志中没有错误,也没有在Wordpress public_html /目录中的error_log

 /log$ ll total 336K drwxr-xr-x 2 www-data root 4.0K Jun 6 18:17 . -rw-rw-r-- 1 www-data root 1.6K Jun 9 14:14 error.log drwxr-xr-x 6 www-data root 4.0K Jun 10 07:23 .. -rw-rw-r-- 1 www-data root 320K Jun 10 07:42 access.log 

在/ etc / log / apache2访问和错误日​​志中,除了重新启动apache2之外,我没有看到任何日志logging

  tail error.log [Wed Jun 10 07:05:15.142372 2015] [mpm_prefork:notice] [pid 6655] AH00169: caught SIGTERM, shutting down [Wed Jun 10 07:05:16.258882 2015] [mpm_prefork:notice] [pid 6873] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations [Wed Jun 10 07:05:16.258960 2015] [core:notice] [pid 6873] AH00094: Command line: '/usr/sbin/apache2' [Wed Jun 10 07:18:45.823428 2015] [mpm_prefork:notice] [pid 6873] AH00169: caught SIGTERM, shutting down [Wed Jun 10 07:18:46.694270 2015] [mpm_prefork:notice] [pid 7210] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations [Wed Jun 10 07:18:46.694345 2015] [core:notice] [pid 7210] AH00094: Command line: '/usr/sbin/apache2' [Wed Jun 10 07:28:36.820319 2015] [mpm_prefork:notice] [pid 7210] AH00169: caught SIGTERM, shutting down [Wed Jun 10 07:28:37.698102 2015] [mpm_prefork:notice] [pid 7472] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations [Wed Jun 10 07:28:37.698179 2015] [core:notice] [pid 7472] AH00094: Command line: '/usr/sbin/apache2' sh: 1: /usr/sbin/sendmail: not found /var/log/apache2# tail access.log ::1 - - [10/Jun/2015:07:38:20 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:38:21 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:38:22 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:38:23 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:38:24 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:38:25 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:38:26 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:42:03 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:42:10 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" ::1 - - [10/Jun/2015:07:42:38 -0400] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 (internal dummy connection)" /public_html$ ll total 216K -rw-r--r-- 1 www-data www-data 3.0K Jan 5 21:17 xmlrpc.php -rw-r--r-- 1 www-data www-data 4.0K Jan 5 21:17 wp-trackback.php -rw-r--r-- 1 www-data www-data 25K Jan 5 21:17 wp-signup.php -rw-r--r-- 1 www-data www-data 11K Jan 5 21:17 wp-settings.php -rw-r--r-- 1 www-data www-data 8.1K Jan 5 21:17 wp-mail.php -rw-r--r-- 1 www-data www-data 33K Jan 5 21:17 wp-login.php -rw-r--r-- 1 www-data www-data 2.7K Jan 5 21:17 wp-load.php -rw-r--r-- 1 www-data www-data 2.4K Jan 5 21:17 wp-links-opml.php -rw-r--r-- 1 www-data www-data 2.9K Jan 5 21:17 wp-cron.php -rw-r--r-- 1 www-data www-data 4.9K Jan 5 21:17 wp-comments-post.php -rw-r--r-- 1 www-data www-data 271 Jan 5 21:17 wp-blog-header.php -rw-r--r-- 1 www-data www-data 4.9K Jan 5 21:17 wp-activate.php -rw-r--r-- 1 www-data www-data 418 Jan 5 21:17 index.php drwxr-xr-x 9 www-data www-data 4.0K Jan 5 22:11 wp-admin -rw-r--r-- 1 www-data www-data 20K Feb 18 22:05 license.txt drwxr-xr-x 12 www-data www-data 4.0K Mar 1 21:57 wp-includes -rw-r--r-- 1 www-data www-data 7.1K May 7 06:30 readme.html -rw-r--r-- 1 www-data www-data 25K May 25 06:23 error_log drwxr-xr-x 6 www-data root 4.0K Jun 10 07:23 .. drwxr-xr-x 8 www-data www-data 4.0K Jun 10 07:26 wp-content -rw-r--r-- 1 www-data www-data 3.3K Jun 10 07:26 wp-config.php -rw-r--r-- 1 www-data www-data 236 Jun 10 07:28 .htaccess drwxr-xr-x 5 www-data www-data 4.0K Jun 10 07:28 . /var/www/html/ total 24K drwxr-xr-x 2 www-data root 4.0K Mar 28 16:00 backups drwxr-xr-x 2 www-data root 4.0K Jun 6 18:17 log drwxr-xr-x 5 root root 4.0K Jun 9 07:12 .. drwxr-xr-x 6 www-data root 4.0K Jun 10 07:23 . drwxr-xr-x 5 www-data www-data 4.0K Jun 10 07:28 public_html 

我怀疑这个问题现在与我的configuration文件中的AllowOveride All指令有关,因为我更新了它们的所有可能性,但仍然收到404错误:

 cat 000-default.conf <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # 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/html #DocumentRoot /var/www # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, eg #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # 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 <Directory "/var/www/html"> AllowOverride All </Directory> </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet cat foobar.com.conf # domain: foobar.com # public: /var/www/foobar.com/public_html/ <VirtualHost *:80> # Admin email, Server Name (domain name), and any aliases ServerAdmin [email protected] ServerName www.foobar.com ServerAlias foobar.com # Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot /var/www/html/foobar.com/public_html # Log file locations LogLevel warn ErrorLog /var/www/html/foobar.com/log/error.log CustomLog /var/www/html/foobar.com/log/access.log combined <Directory /var/www/html/foobar.com/public_html> AllowOverride All Require all granted Order allow,deny Allow from all </Directory> </VirtualHost> 

我也尝试修改.htaccess文件,注意我逐行增加了编辑行,没有任何一行在if语句之外做出了改变。

 cat .htaccess RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress 

许可.htaccess

 -rw-r--r-- 1 www-data www-data 399 Jun 11 07:21 .htaccess 

在我的错误日志中仍然没有任何东西是我的语法正确的000-default.conffoobar.conf文件? 我使用了https://askubuntu.com/questions/429869/is-this-a-correct-way-to-enable-htaccess-in-apache-2-4-7-on-ubuntu-12-04

检查事项:

  • mod_rewrite是否启用? ( sudo a2enmod rewrite
  • 它是否在IfModule块之外工作? 只需删除线条,看看是否改变了事情。

我怀疑第一个选项将解决您的问题。