固定链接不起作用,阿帕奇+CentOS 7

时间:2018-06-24 作者:Damon Hill

我有一个正在运行的CentOS 7和Apache 2 mariadb堆栈,其中包含vhost,让我们加密。我已经使用debian风格(站点可用->站点启用)在虚拟主机上安装了WordPress 4.9.6。

我的问题是我不能使用permalinks。我将我的服务器配置复制到下面。

getenforce 
Disabled
/etc/httpd/sites-available/example.com.conf:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog /var/www/example.com/error.log
    CustomLog /var/www/example.com/requests.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
/etc/httpd/sites-available/example.com-le-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog /var/www/example.com/error.log
    CustomLog /var/www/example.com/requests.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
</VirtualHost>
</IfModule>
Apache配置文件/etc/httpd/conf/httpd.conf:

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    Require all granted 
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
配置。public\\u html目录中的文件/var/www/example.com/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
我已在WordPress admin上启用永久链接设置:

https://example.com/%postname%/
的权限.htaccess 文件包括:

-rw-r--r--1阿帕奇apache 235 Jun 24 13:54。htaccess

sudo httpd -M 显示:

(..)
 rewrite_module (shared)
(..)

1 个回复
最合适的回答,由SO网友:Brad Poulton 整理而成

对于下一个人,请确保在正确的目录中设置AllowOverride All。在Damon的例子中,他在/var/www/html目录中设置了AllowOverride All,但他的站点位于/var/www/example中。com/public\\u html。我可能错了,但AllowOverride设置是特定于目录的。Damon应将AllowOverride All设置添加到/etc/httpd/sites available/example。com。conf和/etc/httpd/可用站点/示例。com le ssl。conf文件。没有此设置。wordpress使用的htaccess文件将起作用。

结束

相关推荐

Pretty permalinks (again)

我正试图在我的WordPress站点中启用永久链接。但每次我尝试更改为除默认链接外的任何永久链接选项时,帖子的链接都会转到404。如果我把它改回来,它就正常工作了。我正在Ubuntu服务器14.04上使用WP 4.2.4和Apache 2.4.7。我做过的事情:我有mod_rewrite 在Apache中启用</我有选择+FollowSymLinks 和AllowOverride All 和RewriteEngine On 在Apache服务器的配置文件中</我已给予书面许可.htaccess