【发布时间】:2019-02-10 00:14:33
【问题描述】:
我正在运行一个 AWS 中型 LAMP 实例。我有三个 Beta 测试 Wordpress 网站都在运行和呈现页面,没有一个是 100% 完成的。服务器软件版本为:
php 7.0.3
httpd apache/2.4.33
WordPress 4.9.8
我花了很多时间研究我的特殊挑战,包括编写一些插件代码来尝试理解问题,我已经接近但还没有解决问题。
我遇到的问题是,当我将永久链接设置更改为 %postname% 时,网站无法找到这些页面。在这个阶段,我只引用页面而不是帖子。我没有对帖子进行任何测试。
我已经确认 mod_rewrite 是使用加载的
sudo apachectl -t -D DUMP_MODULES
and
<?php phpinfo(); ?>
第一个命令将 rewrite_module(共享)列为存在。 php 脚本将 mod_rewrite 显示为已加载模块的一部分。
我关注的一个很好的资源是https://serverfault.com/questions/445599/enabling-mod-rewrite-on-amazon-linux。还有很多其他的,但这似乎抓住了其他搜索提出的所有要点。
从上面我接受了关于测试重定向的建议,它成功了,将我的一个域路由到 wordpress.org。 (为了实现这个测试,我编辑了 /etc/httpd/conf/httpd.conf)
请试试这个:在服务器配置中 - 不是 .htaccess 添加 行 RewriteEngine On 和 RewriteRule ^(.*)$ http://www.wordpress.org/ [R] 确认重写是否在 全部。它应该将所有流量传递到 Wordpress 网站
我还创建了一个基本插件来测试各种 WordPress 功能。我认为一些内部错位可能导致 WordPress 找不到请求的页面。这是错误的 WordPress 在将页面 ID 传递给 get_permalink() 函数时找到了正确的页面。
我只是添加了一个 echo get_permalink(290);到我的简单插件代码。这正确地呼应了
https://www.mydomainname.com/correct-slug-for-page-290
如果我复制并粘贴上面的 URL 失败。
注意:当我修改我的永久链接设置时,.htaccess 文件会自动修改/更新。
如果我将 WordPress 永久链接设置为普通,一切正常。
如果我将 WordPress 永久链接设置为自定义并使用 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
我的 httpd.conf 中包含大部分 cmets 的片段已被删除。一旦我可以让这个基本功能正常工作,我确实计划回去并收紧一些设置。
欣赏任何见解、提示或建议。谢谢大家。
#
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>
【问题讨论】:
标签: php wordpress .htaccess mod-rewrite permalinks