wordpress 永久链接不起作用 - htaccess 似乎没问题,但在页面上出现 404 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19400749/
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
wordpress permalinks not working - htaccess seems ok but getting 404 error on pages
提问by babbaggeii
I updated the permalink structure to /%postname%/ and this updated my .htaccess with:
我将永久链接结构更新为 /%postname%/ 并将我的 .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
But I still get 404 errors on the pages. Are there any other settings that I need to change?
但我仍然在页面上收到 404 错误。是否还有其他设置需要更改?
Edit: if it helps the apache log seems to be looking directly in the permalinked folder. I.e.:
编辑:如果它有助于 apache 日志似乎直接在永久链接的文件夹中查找。IE:
[Wed Oct 16 11:12:32 2013] [error] [client xx.xx.xx.xxx] File does not exist: /var/www/exampledomain/news, referer: http://exampledomain.com/
回答by MTLHD777
For other people landing on this page -Another issue could be (If you are using Apache as your web server) is your httpd.conf or your sites-available/sitename.conf file needs editing.
对于登陆此页面的其他人 -另一个问题可能是(如果您使用 Apache 作为您的 Web 服务器)是您的 httpd.conf 或您的 sites-available/sitename.conf 文件需要编辑。
Your web directory will need to allow the .htaccess file to override it's settings.
您的 Web 目录需要允许 .htaccess 文件覆盖其设置。
look for your web dir in the file - it will be in the bulk of the conf file or segregated into a VirtualHost section.
在文件中查找您的 web 目录 - 它将位于大部分 conf 文件中或隔离到 VirtualHost 部分。
<Directory /path/to/site>
#add the following setting to allow .htaccess in your web dir to work
AllowOverride FileInfo
#other settings ---
</Directory>
This will allow you to set up WordPress URLs however you want, within WordPress.
这将允许您在 WordPress 中随意设置 WordPress URL。
***Edited - Thank You nietonfir For update. Use the least amount of privilege at first. If this doesn't work then replace AllowOverride FileInfo
with AllowOverride All
*** 已编辑 - 谢谢 nietonfir 更新。首先使用最少的权限。如果这不起作用,则替换AllowOverride FileInfo
为AllowOverride All
回答by gan
There can be multiple things preventing the rewrite rule from working. My ubuntu server needed 3 things changed to get permalinks working.
可能有多种因素阻止重写规则起作用。我的 ubuntu 服务器需要改变 3 件事才能使永久链接正常工作。
In newer versions of apache2, you need to enable the module:
在较新版本的 apache2 中,您需要启用该模块:
sudo a2enmod rewrite
sudo service apache2 restart
You may also need to modify the apache2.conf file.
您可能还需要修改 apache2.conf 文件。
sudo nano /etc/apache2/apache2.conf
Change your web directory override rule to AllowOverride All.
将您的 Web 目录覆盖规则更改为AllowOverride All。
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After that, restart the service again.
之后,再次重新启动服务。
The .htaccess file in the WordPress install directory needs to be owned or readable/modifiable by the webserver.
WordPress 安装目录中的 .htaccess 文件需要由网络服务器拥有或可读/可修改。
This can be accomplished by changing owner to www-data (usually the webserver user), or changing permissions.
这可以通过将所有者更改为 www-data(通常是网络服务器用户)或更改权限来实现。
sudo chown www-data /var/www/wordpress-install/.htaccess
OR
或者
sudo chmod 664 /var/www/wordpress-install/.htaccess
Login to your Wordpress admin backend and save the permalink settings, and they should hopefully be working.
登录到您的 Wordpress 管理后端并保存永久链接设置,它们应该可以正常工作。
回答by babbaggeii
This is now solved. I hadn't enabled mod_rewrite. So I did this:
现在已经解决了。我没有启用 mod_rewrite。所以我这样做了:
$ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
$ service apache2 restart
* Restarting web server apache2
回答by Anonymous Platypus
You would want to tell apache to follow your .htaccess file. You can do this by editing the apache.conf file
您想告诉 apache 跟随您的 .htaccess 文件。您可以通过编辑 apache.conf 文件来做到这一点
$sudo nano /etc/apache2/apache.conf
Scroll down to the line By default it will be:
向下滚动到该行默认情况下它将是:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
change the value of AllowOverride to All so now it becomes:
将 AllowOverride 的值更改为 All,现在变为:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Press ctrl+x and press y to save the configuration file. In order to make this changes to server first enable the mod_rewrite by.
按 ctrl+x 并按 y 保存配置文件。为了对服务器进行此更改,首先启用 mod_rewrite by。
$ sudo a2enmod rewrite
And then restart the server
然后重启服务器
$ sudo service apache2 restart
Done!
完毕!
Source: https://www.wst.space/riddling-with-wordpress-permalink-setup-issues/
来源:https: //www.wst.space/riddling-with-wordpress-permalink-setup-issues/
回答by Krunal Shah
use below .htaccess code, just put your project name (which is in www directory) in below code
使用下面的 .htaccess 代码,只需将您的项目名称(在 www 目录中)放在下面的代码中
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project_name/index.php [L]
</IfModule>
# END WordPress
Thanks
谢谢
回答by Rick Gladwin
One more thing to check if this describes your problem:
还有一件事要检查这是否描述了您的问题:
- htaccess and mod_rewrite are set up correctly
- 404 error on some permalinks but not others
- htaccess 和 mod_rewrite 设置正确
- 某些固定链接出现 404 错误,但其他固定链接则不然
Ensure that there are no existing .php files or directories in the same folder as your Wordpress install with names matching a Wordpress permalink.
确保与 Wordpress 安装相同的文件夹中没有现有的 .php 文件或目录,其名称与 Wordpress 永久链接匹配。
For example, if you have the following Wordpress page permalinks:
例如,如果您有以下 Wordpress 页面永久链接:
example.com/name_one/
example.com/name_two/
and the directory containing your Wordpress install includes the following file:
包含您的 Wordpress 安装的目录包含以下文件:
name_one.php
then this will be the result:
那么这将是结果:
- http://example.com/name_two/– this permalink will work
- http://example.com/name_one/– this permalink will NOTwork
- http://example.com/name_two/– 这个永久链接会起作用
- http://example.com/name_one/-这将固定链接不工作
More importantly, the second URL will give a 404 instead of running name_one.php, meaning this problem is hard to diagnose, as it can give the same symptoms as an incorrectly written .htaccess file.
更重要的是,第二个 URL将给出 404 而不是运行 name_one.php,这意味着这个问题很难诊断,因为它可以给出与错误编写的 .htaccess 文件相同的症状。
回答by Magnus
If you are setting up a new or cloned siteon ubuntu, remember to symlink the site configuration file e.g. /etc/apache2/sites-available/your-file.conf
to the /etc/apache2/sites-enabled
folder so apache loads it.
如果您正在设置新的或克隆的网站在Ubuntu,请记住符号链接的站点配置文件,例如/etc/apache2/sites-available/your-file.conf
到/etc/apache2/sites-enabled
文件夹,以便阿帕奇加载它。
Just run: sudo a2ensite your-file.conf
, then sudo service apache2 reload
.
只需运行:sudo a2ensite your-file.conf
,然后sudo service apache2 reload
。
sudo a2dissite your-file.conf
to remove symlink i.e. disable config.
sudo a2dissite your-file.conf
删除符号链接,即禁用配置。
回答by ganchclub
I was facing with the same problem and had one more thing to look for.
我面临着同样的问题,还有一件事要寻找。
Here is what you need to do for wordpress permalinks work properly:
要使 wordpress 永久链接正常工作,您需要执行以下操作:
Make sure you have the proper permission modes for files and folders in your wordpress directory:
sudo find . -type f -exec chmod 644 {} +
sudo find . -type d -exec chmod 755 {} +
For permalink structure make sure
mode_rewrite
is enabled in apache:sudo a2enmod rewrite
sudo service apache2 restart
确保您的 wordpress 目录中的文件和文件夹具有正确的权限模式:
sudo find . -type f -exec chmod 644 {} +
sudo find . -type d -exec chmod 755 {} +
对于永久链接结构,请确保
mode_rewrite
在 apache 中启用:sudo a2enmod rewrite
sudo service apache2 restart
回答by khurram
Users of WAMP (Windows): Some versions of WAMP (all versions?) do not enable mod_rewrite or permit following SymLinks by default. To enable the required functionality navigate to the apache/conf/httpd.conf file
, open with a text editor and uncomment the line LoadModule rewrite_module modules/mod_rewrite
.so (i.e., delete the hash/pound sign at the front of the line). Then further down in the same file there is a section that starts with the line "Options FollowSymlinks". Change the second line in that section from "AllowOverride none
" to AllowOverride all
. Save edited httpd.conf and restart all WAMP modules. Your permalinks should now work.
WAMP (Windows) 用户:WAMP 的某些版本(所有版本?)默认情况下不启用 mod_rewrite 或允许跟随 SymLinks。要启用所需的功能,请导航到apache/conf/httpd.conf file
,使用文本编辑器打开并取消注释LoadModule rewrite_module modules/mod_rewrite
.so行(即删除该行前面的井号/井号)。然后在同一个文件中,有一个以“ Options FollowSymlinks”行开头的部分。将该部分中的第二行从 " AllowOverride none
" 更改为AllowOverride all
. 保存编辑的 httpd.conf 并重新启动所有 WAMP 模块。您的永久链接现在应该可以工作了。
回答by Jeff
Yet another possibility: I just updated my macOS which alwaysscrews up the Apache config file. Among other things, I also had to re-enable the mod_rewrite
module. Find the line that says,
另一种可能性:我刚刚更新了我的 macOS,它总是搞砸了 Apache 配置文件。除此之外,我还必须重新启用该mod_rewrite
模块。找到说,
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
And remove the hash so it says,
并删除哈希所以它说,
LoadModule rewrite_module libexec/apache2/mod_rewrite.so