Php Wordpress永久链接行为

Php Wordpress永久链接行为,php,wordpress,.htaccess,mod-rewrite,permalinks,Php,Wordpress,.htaccess,Mod Rewrite,Permalinks,我正在运行一个AWS中灯实例。我有三个测试版的Wordpress网站都在运行和呈现页面,没有一个是100%完整的。服务器软件版本包括: PHP7.0.3 httpd-apache/2.4.33 Wordpress 4.9.8 我已经花了相当多的时间研究我的特殊挑战,包括编写一些插件代码来尝试理解这个问题,我正在接近但还没有解决这个问题 我遇到的问题是,当我将永久链接设置更改为%postname%时,站点无法定位页面。在这个阶段,我只引用页面而不是帖子。我没有做任何测试与职位 我已经确认mod_r

我正在运行一个AWS中灯实例。我有三个测试版的Wordpress网站都在运行和呈现页面,没有一个是100%完整的。服务器软件版本包括:

PHP7.0.3

httpd-apache/2.4.33

Wordpress 4.9.8

我已经花了相当多的时间研究我的特殊挑战,包括编写一些插件代码来尝试理解这个问题,我正在接近但还没有解决这个问题

我遇到的问题是,当我将永久链接设置更改为%postname%时,站点无法定位页面。在这个阶段,我只引用页面而不是帖子。我没有做任何测试与职位

我已经确认mod_rewrite是使用

sudo apachectl -t -D DUMP_MODULES
and
<?php phpinfo(); ?>
如果我复制并粘贴上面的URL,它将失败

注意:当我修改永久链接设置时,.htaccess文件会自动修改/更新

如果我将我的WordPress永久链接设置设置为普通,一切都会正常工作

如果我将WordPress permalink设置设置为custom并使用index.php/%postname%/所有链接解析。(存在和不存在.htaccess文件)

如果我将永久链接设置仅设置为%postname%,则所有内容都将成为404错误。设置为%postname%时,wordpress会自动创建以下文件

-rw-r--r-- 1 apache www 235 Sep  4 21:47 .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
-rw-r--r--1 apache www.235 Sep 4 21:47.htaccess
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
我的httpd.conf中包含大多数注释的代码片段将被编辑掉。一旦我能让这个基本功能发挥作用,我确实计划回去并收紧一些设置

感谢任何见解、提示或建议。谢谢大家

#
ServerRoot "/etc/httpd"


Listen 80

Include conf.modules.d/*.conf


User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride All
    Require all granted
</Directory>

DocumentRoot "/var/www/html"

#
# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride All
    # Allow open access:
    Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
    Options Indexes FollowSymLinks

    AllowOverride All

    Require all granted
</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<Files ".ht*">
    Require all denied
</Files>


<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>


EnableSendfile on

# Supplemental configuration
#
# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf

<VirtualHost *:80>
    ServerAdmin webmaster@beta-test-one.com
    DocumentRoot /var/www/html/beta-test-one.com
    ServerName beta-test-one.com
    ServerAlias www.beta-test-one.com
    RewriteEngine On
    <IF "req('Host') != 'www.beta-test-one.com'">
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://www.%{HTTP:Host}%{REQUEST_URI} [L,R=301]
    </IF>
    <ELSE>
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=301]
    </ELSE>
    ErrorLog logs/beta-test-one.com-error_log
    CustomLog logs/beta-test-one.com-access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@beta-test-two.com
    DocumentRoot /var/www/html/beta-test-two.com
    <Directory "/var/www/html/beta-test-two.com">
    AllowOverride All
    </Directory>
    ServerName beta-test-two.com
    ServerAlias www.beta-test-two.com
    RewriteEngine On
    <IF "req('Host') != 'www.beta-test-two.com'">
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://www.%{HTTP:Host}%{REQUEST_URI} [L,R=301]
    </IF>
    <ELSE>
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=301]
    </ELSE>
    ErrorLog logs/beta-test-two.com-error_log
    CustomLog logs/beta-test-two.com-access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@beta-test-three.com.au
    DocumentRoot /var/www/html/beta-test-three.com.au
    ServerName beta-test-three.com.au
    ServerAlias www.beta-test-three.com.au
    RewriteEngine On
    <IF "req('Host') != 'www.beta-test-three.com.au'">
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://www.%{HTTP:Host}%{REQUEST_URI} [L,R=301]
    </IF>
    <ELSE>
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=301]
    </ELSE>
    ErrorLog logs/beta-test-three.com-error_log
    CustomLog logs/beta-test-three.com-access_log common
</VirtualHost>
#
ServerRoot“/etc/httpd”
听80
包括conf.modules.d/*.conf
用户apache
组apache
服务器管理员root@localhost
允许超越所有
要求所有授权
DocumentRoot“/var/www/html”
#
#放宽对/var/www内内容的访问。
#
允许超越所有
#允许开放访问:
要求所有授权
#进一步放宽对默认文档根目录的访问:
选项索引跟随符号链接
允许超越所有
要求所有授权
#
#DirectoryIndex:设置Apache在目录
#请求。
#
DirectoryIndex.html
#
#以下几行阻止.htaccess和.htpasswd文件被删除
#由Web客户端查看。
#
要求全部拒绝
ScriptAlias/cgi-bin/“/var/www/cgi-bin/”
不允许超限
选项无
要求所有授权
TypesConfig/etc/mime.types
AddType应用程序/x-compress.Z
AddType应用程序/x-gzip.gz.tgz
AddType text/html.shtml
AddOutputFilter包括.shtml
在上启用SendFile
#补充配置
#
#加载“/etc/httpd/conf.d”目录中的配置文件(如果有)。
IncludeOptional conf.d/*.conf
服务器管理员webmaster@beta-test-one.com
DocumentRoot/var/www/html/beta-test-one.com
ServerName beta-test-one.com
ServerAlias www.beta-test-one.com
重新启动发动机
RewriteCond%{HTTP:X-Forwarded-Proto}=HTTP
重写规则。*https://www.%{HTTP:Host}%{REQUEST_URI}[L,R=301]
RewriteCond%{HTTP:X-Forwarded-Proto}=HTTP
重写规则。*https://%{HTTP:Host}%{REQUEST_URI}[L,R=301]
错误日志/beta-test-one.com-error\u日志
自定义日志/beta-test-one.com-access\u日志公用
服务器管理员webmaster@beta-测试二
DocumentRoot/var/www/html/beta-test-two.com
允许超越所有
ServerName beta-test-two.com
ServerAlias www.beta-test-two.com
重新启动发动机
RewriteCond%{HTTP:X-Forwarded-Proto}=HTTP
重写规则。*https://www.%{HTTP:Host}%{REQUEST_URI}[L,R=301]
RewriteCond%{HTTP:X-Forwarded-Proto}=HTTP
重写规则。*https://%{HTTP:Host}%{REQUEST_URI}[L,R=301]
错误日志/beta-test-two.com-error\u日志
自定义日志/beta-test-two.com-access\u日志公用
服务器管理员webmaster@beta-test-three.com.au
DocumentRoot/var/www/html/beta-test-three.com.au
ServerName beta-test-three.com.au
ServerAlias www.beta-test-three.com.au
重新启动发动机
RewriteCond%{HTTP:X-Forwarded-Proto}=HTTP
重写规则。*https://www.%{HTTP:Host}%{REQUEST_URI}[L,R=301]
RewriteCond%{HTTP:X-Forwarded-Proto}=HTTP
重写规则。*https://%{HTTP:Host}%{REQUEST_URI}[L,R=301]
错误日志/beta-test-three.com-error\u日志
自定义日志/beta-test-three.com-access\u日志公用

问题现在解决了

我开始检查我的mod_重写设置。我意识到我已经在httpd.conf文件中进行了测试,但没有在.htaccess级别测试重定向,这是根据以下文章中的一些提示进行的

结果是.htaccess文件被绕过

最终的罪魁祸首是httpd.conf文件中显式重定向到https

 RewriteEngine On <IF "req('Host') != 'www.beta-test-three.com.au'">
 RewriteCond %{HTTP:X-Forwarded-Proto} =http RewriteRule .*
 https://www.%{HTTP:Host}%{REQUEST_URI} [L,R=301] </IF> <ELSE>
 RewriteCond %{HTTP:X-Forwarded-Proto} =http RewriteRule .*
 https://%{HTTP:Host}%{REQUEST_URI} [L,R=301] </ELSE>
 RewriteEngine On <IF "req('Host') != 'www.beta-test-three.com.au'">
 RewriteCond %{HTTP:X-Forwarded-Proto} =http RewriteRule .*
 https://www.%{HTTP:Host}%{REQUEST_URI} [L,R=301] </IF> <ELSE>
 RewriteCond %{HTTP:X-Forwarded-Proto} =http RewriteRule .*
 https://%{HTTP:Host}%{REQUEST_URI} [L,R=301] </ELSE>
define('WP_HOME','https://www.domain-name.com');
define('WP_SITEURL','https://www.domain-name.com');

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
       $_SERVER['HTTPS']='on';