Wordpress 中的永久链接 - 找不到页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12410921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Permalinks in Wordpress - Page not found
提问by darksoulsong
I've been searching for hours but haven't found anything that seems to be able to solves this issue.
我已经搜索了几个小时,但没有找到任何似乎能够解决这个问题的东西。
Here's the scenario:
这是场景:
I'm making a wp theme based on the "Twenty Eleven" theme. Everything went fine til I decided to change the urls to permalinks. The only page being displayed is the static page that I have defined earlier.
我正在制作一个基于“二十一点”主题的 wp 主题。一切都很顺利,直到我决定将 url 更改为永久链接。唯一显示的页面是我之前定义的静态页面。
I have set up the htacces file. In fact, WP did it automatically. Everything works if I switch back to the default setting, but, for SEO, I would rather use the permalinks option.
我已经设置了 htacces 文件。事实上,WP 是自动完成的。如果我切换回默认设置,一切都会正常,但是,对于 SEO,我宁愿使用永久链接选项。
Here is my htaccess file (it is on my WP installation folder):
这是我的 htaccess 文件(它在我的 WP 安装文件夹中):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite/index.php [L]
</IfModule>
# END WordPress
I have seen this post wordpress .htaccess with permalinksbut nothing there could help me. Any help would be very nice.
我看过这篇带有永久链接的wordpress .htaccess帖子,但没有任何内容可以帮助我。任何帮助都会非常好。
UPDATE :Things I have tried already:
更新:我已经尝试过的事情:
- Delete pages and create again.
- Access the permalink field on wp_options (db) and setting the value to blank and set the permalink option in the admin again.
- I′m running it on windows 7 through an apache2 installation of Zend Server.
- I thought it was a problem related to my localhost environment, so I put the site online. No luck at all. I'm assuming that wordpress can′t change permalinks to a more friendly url type when you set a static front page. What a shame.
- 删除页面并重新创建。
- 访问 wp_options (db) 上的永久链接字段并将值设置为空白并再次在管理员中设置永久链接选项。
- 我通过 Zend Server 的 apache2 安装在 Windows 7 上运行它。
- 我以为是我的本地主机环境的问题,所以我把网站放到了网上。一点运气都没有。我假设当您设置静态首页时,wordpress 无法将永久链接更改为更友好的 url 类型。多可惜。
回答by Skillachie
For those using apache. You will need to
对于那些使用 apache 的人。你需要
- Ensure you have .htaccess in root path of the site you are hosting. Example /var/www
- Update the /etc/apache2/sites-available/default
- 确保您在托管站点的根路径中有 .htaccess。示例 /var/www
- 更新 /etc/apache2/sites-available/default
From
从
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
To
到
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Hope this helps someone
希望这有助于某人
回答by Knyaz
I don't know if you have found the solution to it, but I solved this problem by simply turning on LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf file.
我不知道您是否找到了解决方案,但我通过简单地打开 httpd.conf 文件中的 LoadModule rewrite_module modules/mod_rewrite.so 解决了这个问题。
回答by dekarpaulvictor
If editing apache2's default configuration and Wordpress' .htaccess
files don't help the reason could simply be that apache2's rewrite
module is not enabled. This is usually the case for those who install apache2 themselves. Wordpress needs apache2's rewrite
module enabled to support permalink edits. If, like me, you'd rather not edit conf files by hand, apache2's rewrite
module can be enabled by running these commands as root (I'm using Ubuntu 18.04 but I'm sure the commands aren't different for other distros):
如果编辑 apache2 的默认配置和 Wordpress 的.htaccess
文件没有帮助,原因可能只是 apache2 的rewrite
模块未启用。这通常是那些自己安装 apache2 的人的情况。Wordpress 需要rewrite
启用apache2 的模块来支持永久链接编辑。如果像我一样,您不想手动编辑 conf 文件,rewrite
则可以通过以 root 身份运行这些命令来启用apache2 的模块(我使用的是 Ubuntu 18.04,但我确定其他发行版的命令没有不同):
a2enmod rewrite
and restart the apache2 service by running:
并通过运行以下命令重新启动 apache2 服务:
systemctl restart apache2
or
或者
service apache2 restart
If you're running Ubuntu 18.04, you can check out all available apache2 modules under /etc/apache2/mods-available
and see what modules are enabled by listing the files under /etc/apache2/mods-enabled
.
如果您运行的是 Ubuntu 18.04,您可以查看下所有可用的 apache2 模块,/etc/apache2/mods-available
并通过列出/etc/apache2/mods-enabled
.
回答by Anthony
Also see Permalinks on WordPress (Amazon EC2)
另请参阅WordPress (Amazon EC2) 上的永久链接
I had the same problem, but the author in the above link suggested to do three things (it worked for me!):
我遇到了同样的问题,但上面链接中的作者建议做三件事(它对我有用!):
Go to /etc/httpd/conf
and edit httpd.conf
前往/etc/httpd/conf
并编辑httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
Change also AllowOverride if it is set to None
如果设置为 None,也更改 AllowOverride
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
I you haven't created it yet, place in the root directory of your wordpress installation a .htaccess file with the following contents:
我还没有创建它,在你的 wordpress 安装的根目录中放置一个 .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
回答by Zareef Hasan
There are two 'Directory' sections in the httpd.conf file. One is for root folder and another for htdocs folder. You must edit both fields to make WordPress pages work again. Hope it helps.
httpd.conf 文件中有两个“目录”部分。一个用于根文件夹,另一个用于 htdocs 文件夹。您必须编辑这两个字段才能使 WordPress 页面再次工作。希望能帮助到你。
回答by IVIike
This worked for me like @Skillachie wrote BUT be also sure to include those settings in the 000-default-SSL.conf file if you use SSL!
这对我有用,就像@Skillachie 写的一样,但如果您使用 SSL,请确保将这些设置包含在 000-default-SSL.conf 文件中!
<Directory /var/www/PATH>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>