为什么我的 .htaccess 无法在这个 VPS 上运行?

为什么我的 .htaccess 无法在这个 VPS 上运行?

我有以下 .htaccess 文件/public_html/.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

以下是 Ubuntu 14 服务器上我的 public_html/ 目录的权限 Wordpress 4.1 Apache 2.4 我有几乎相同的 Wordpress 网站和相同的 .htaccess 文件,我不明白为什么我的 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 的日志记录外,我没有看到任何其他内容

    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

我怀疑该问题现在与我的配置文件中的指令有关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, e.g.
    #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.conf我的错误日志中仍然没有任何内容,我在和文件上的语法是否正确foobar.conf?我使用了https://askubuntu.com/questions/429869/is-this-a-correct-way-to-enable-htaccess-in-apache-2-4-7-on-ubuntu-12-04

答案1

检查事项:

  • mod_rewrite 是否启用?( sudo a2enmod rewrite)
  • 它在 IfModule 块之外有效吗?只需删除这些行,看看是否会发生改变。

我认为第一个选项可以解决你的问题。

相关内容