[英]“The requested URL /projectname/pagename/ was not found on this server.” issue on WordPress website
For my WordPress project, I am getting the error The requested URL /projectname/pagename/ was not found on this server.
对于我的WordPress项目,我收到错误The requested URL /projectname/pagename/ was not found on this server.
when I try to set the permalink to Postname: http://10.60.8.118/projectname/sample-post/
. 当我尝试将永久链接设置为Postname: http://10.60.8.118/projectname/sample-post/
。 The project is hosted on my Ubuntu machine. 该项目托管在我的Ubuntu机器上。
I am able to view the pages or posts with permalinks set as Plain: http://10.60.8.118/projectname/?p=123
我可以查看固定链接设置为Plain: http://10.60.8.118/projectname/?p=123
的页面或帖子Plain: http://10.60.8.118/projectname/?p=123
Earlier .htaccess was not writable. 早些时候.htaccess不可写。 So I changed it and now it is writable. 所以我改变了它,现在它是可写的。
content of .htaccess .htaccess的内容
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /devcounsyl/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The above settings does not work. 以上设置不起作用。 I have also tried changing the base to / (I guess it should be /devcounsyl/ but none of them works.) 我也尝试将基数更改为/(我想它应该是/ devcounsyl /但它们都不起作用。)
content of .htaccess .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
Also tried: Changing file and folder permissions assuming that that might be causing the issue: 还尝试了:更改文件和文件夹权限,假设可能导致问题:
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
database urls: 数据库网址:
wp_options
table has the value http://10.60.8.118/devcounsyl
for siteurl
and home
对于siteurl
和home
wp_options
表的值为http://10.60.8.118/devcounsyl
Project structure: 项目结构:
/var/www/html/devcounsyl/
The WordPress files are in the project folder and also the .htaccess
file is in devcounsyl
project folder. WordPress文件位于项目文件夹中,而.htaccess
文件位于devcounsyl
项目文件夹中。
Turns out that .htaccess
was not the issue for me. 事实证明.htaccess
对我来说不是问题。 The issue was in server configuration file. 问题出在服务器配置文件中。 Posting my answer in case any one bumps into similar issue and looking for a solution. 发布我的答案,以防任何人遇到类似问题并寻找解决方案。
For AWS EC2 server: 对于AWS EC2服务器:
Step 1: Edit configuration file 第1步:编辑配置文件
sudo nano /etc/httpd/conf/httpd.conf
Edit this file and change 编辑此文件并进行更改
<Directory /var/www/html/wordpress/>
AllowOverride None
</Directory>
to 至
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
Note that here, /var/www/html/wordpress/
is path to the root folder where WordPress project was hosted. 请注意, /var/www/html/wordpress/
是托管WordPress项目的根文件夹的路径。
Step 2: Restart server 第2步:重启服务器
Please don't forget to restart your server after you do the changes to the .conf
file. 在对.conf
文件进行更改后,请不要忘记重新启动服务器。
sudo service httpd restart
For Ubuntu server: 对于Ubuntu服务器:
Step 1: Edit configuration file 第1步:编辑配置文件
sudo gedit /etc/apache2/apache2.conf
Edit this file and change 编辑此文件并进行更改
<Directory /var/www/html/wordpress/>
AllowOverride None
</Directory>
to 至
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
Note that here, /var/www/html/wordpress/
is path to the root folder where WordPress project was hosted. 请注意, /var/www/html/wordpress/
是托管WordPress项目的根文件夹的路径。
Step 2: Restart server 第2步:重启服务器
Please don't forget to restart your server after you do the changes to the .conf
file. 在对.conf
文件进行更改后,请不要忘记重新启动服务器。
sudo service apache2 restart
If WordPress is installed in a subdirectory then you should move your .htaccess
into that subdirectory (if not already) and remove the slash prefix from the RewriteRule
substitution , otherwise the RewriteBase
directive will have no effect. 如果WordPress安装在子目录中,那么你应该将.htaccess
移动到该子目录(如果还没有)并从RewriteRule
替换中删除斜杠前缀,否则RewriteBase
指令将不起作用。 For example: 例如:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteBase is not required if .htaccess file is in the /devcounsyl dir
#RewriteBase /devcounsyl/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Although, if the .htaccess
file is already in the /devconsyl
subdirectory, then the RewriteBase
directive is not actually required (providing you remove the slash prefix from the RewriteRule
substitution , as mentioned above). 虽然,如果.htaccess
文件已经在/devconsyl
子目录中,那么实际上并不需要RewriteBase
指令( RewriteBase
您从RewriteRule
替换中删除了斜杠前缀,如上所述)。
The .htaccess
file would need to be in the WordPress subdirectory for the first RewriteRule
to match. .htaccess
文件需要在WordPress子目录中才能匹配第一个RewriteRule
。 (ie. RewriteRule ^index\\.php$ - [L]
) (即RewriteRule ^index\\.php$ - [L]
)
By removing the slash prefix, you are making the substitution relative to the directory containing the .htaccess
file. 通过删除斜杠前缀,您将相对于包含.htaccess
文件的目录进行替换 。 The RewriteBase
only applies to relative substitutions and simply overrides the default (relative) path. RewriteBase
仅适用于相对替换,并简单地覆盖默认(相对)路径。
If, however, the .htaccess
file is located in the document root of your domain (ie. not the WordPress root) then you would need to modify your .htaccess
like this: 但是,如果.htaccess
文件位于域的文档根目录中(即不是WordPress根目录),那么您需要修改.htaccess
如下所示:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteBase is required if .htaccess file is in document root
RewriteBase /devcounsyl/
RewriteRule ^devcounsyl/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.