简体   繁体   English

找不到404的Wordpress永久链接

[英]Wordpress Permalinks resulting in 404 not found

I cannot seem to get my permalinks working for my WordPress site. 我似乎无法让我的永久链接在我的WordPress网站上正常工作。

My WordPress homepage, and wp-admin work fine, just none of my sub-pages work. 我的WordPress主页和wp-admin都可以正常工作,但我的所有子页面均无法正常工作。

I've been mucking about with my .htaccess file, and site.conf files, but I cannot seem to get this working. 我一直在想弄我的.htaccess文件和site.conf文件,但似乎无法正常工作。

For context, I have the following file structure: 对于上下文,我具有以下文件结构:

Root
|--.htaccess
|--wordpress
|--|--index.php

Path: /var/www/html/domain.ca/public_html/wordpress 路径: /var/www/html/domain.ca/public_html/wordpress

Here is my current .htaccess config: 这是我当前的.htaccess配置:

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?domain.ca$
    RewriteCond %{REQUEST_URI} !^/wordpress/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /wordpress/$1
    RewriteCond %{HTTP_HOST} ^(www.)?domain.ca$
    RewriteRule ^(/)?$ wordpress/index.php [L] 
</IfModule>
# END WordPress

And here is my current site.conf file: 这是我当前的site.conf文件:

<VirtualHost *:80>
        ServerAdmin email@email.com
        ServerName domain.ca
        ServerAlias www.domain.ca
        DocumentRoot /var/www/html/domain.ca/public_html

        <Directory /var/www/html/domain.ca/public_html>
               Options Indexes FollowSymLinks
               AllowOverride All
               Require all granted
        </Directory>

        LogLevel alert rewrite:trace3
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

I've already tried going into wp-admin and re-saving permalinks, that simply makes things worse as it seems to default my .htaccess to one that is designed for WordPress installed in root, and not a sub directory. 我已经尝试过进入wp-admin并重新保存永久链接,这只会使情况变得更糟,因为它似乎默认将我的.htaccess设置为专为根目录而不是子目录安装的WordPress设计的。

I've also ensured that mod_rewrite is enabled in Apache, and I have rebooted the server. 我还确保在Apache中启用了mod_rewrite,并重新启动了服务器。

Your Virtualhost is good and you should keep default wp .htaccess as it is generated automatically as soon as you set the permalinks (at least between the 2 commented lines #BEGIN and #END WordPress ) 您的Virtualhost很好,您应该保留默认的wp .htaccess,因为它会在您设置永久链接后自动生成(至少在两条注释行#BEGIN#END WordPress

Quoted from https://wordpress.org/support/article/giving-wordpress-its-own-directory/#method-ii-with-url-change 引自https://wordpress.org/support/article/giving-wordpress-its-own-directory/#method-ii-with-url-change

I guess points 1, 5 and 10 are already done for you but it might help future readers to. 我想第1、5和10点已经为您完成,但可能会帮助将来的读者。

  1. Create the new location for the core WordPress files to be stored (we will use /wordpress in our examples). 为要存储的核心WordPress文件创建新位置(在示例中,我们将使用/ wordpress)。 (On linux, use mkdir wordpress from your www directory. You'll probably want to use chown apache:apache on the wordpress directory you created.) (在Linux上,从www目录中使用mkdir wordpress。您可能要在创建的wordpress目录中使用chown apache:apache。)

  2. Go to the General Screen. 转到常规屏幕。

  3. In WordPress address (URL): set the address of your main WordPress core files. 在WordPress地址(URL)中:设置主要WordPress核心文件的地址。 Example: http://example.com/wordpress 示例: http//example.com/wordpress

  4. In Site address (URL): set root directory's URL. 在站点地址(URL)中:设置根目录的URL。 Example: http://example.com 范例: http//example.com

  5. Now move your WordPress core files (from root directory) to the subdirectory. 现在,将WordPress核心文件(从根目录)移动到子目录。

  6. Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress directory into the root directory of your site (Blog address). 将WordPress目录中的index.php和.htaccess文件复制(不移动!)到您网站的根目录(博客地址)中。 The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. .htaccess文件是不可见的,因此您可能必须将FTP客户端设置为显示隐藏文件。 If you are not using pretty permalinks, then you may not have a .htaccess file. 如果您没有使用漂亮的永久链接,则可能没有.htaccess文件。 If you are running WordPress on a Windows (IIS) server and are using pretty permalinks, you'll have a web.config rather than a .htaccess file in your WordPress directory. 如果您在Windows(IIS)服务器上运行WordPress并使用漂亮的永久链接,则WordPress目录中将有一个web.config文件而不是.htaccess文件。 For the index.php file the instructions remain the same, copy (don't move) the index.php file to your root directory. 对于index.php文件,说明仍然相同,请将index.php文件复制(不要移动)到您的根目录中。 The web.config file, must be treated differently than the .htaccess file so you must MOVE (DON'T COPY) the web.config file to your root directory. 必须将web.config文件与.htaccess文件区别对待,因此您必须将web.config文件移动(不要复制)到根目录中。

  7. Open your root directory's index.php file in a text editor 在文本编辑器中打开根目录的index.php文件

  8. Change the following and save the file. 更改以下内容并保存文件。 Change the line that says:require( dirname( FILE ) . '/wp-blog-header.php' );to the following, using your directory name for the WordPress core files:require( dirname( FILE ) . '/wordpress/wp-blog-header.php' ); 使用WordPress核心文件的目录名称,将以下行改为:require(dirname( FILE )。'/ wp-blog-header.php');更改为以下内容:require(dirname( FILE )。'/ wordpress / wp-blog-header.php');

  9. Login to the new location. 登录到新位置。 It might now be http://example.com/wordpress/wp-admin/ 现在可能是http://example.com/wordpress/wp-admin/

  10. If you have set up Permalinks, go to the Permalinks Screen and update your Permalink structure. 如果已设置永久链接,请转到永久链接屏幕并更新您的永久链接结构。 WordPress will automatically update your .htaccess file if it has the appropriate file permissions. 如果WordPress具有适当的文件权限,它将自动更新.htaccess文件。 If WordPress can't write to your .htaccess file, it will display the new rewrite rules to you, which you should manually copy into your .htaccess file (in the same directory as the main index.php file.) 如果WordPress无法写入您的.htaccess文件,它将向您显示新的重写规则,您应将其手动复制到.htaccess文件中(与主index.php文件位于同一目录中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM