简体   繁体   中英

Wordpress Permalinks resulting in 404 not found

I cannot seem to get my permalinks working for my WordPress site.

My WordPress homepage, and wp-admin work fine, just none of my sub-pages work.

I've been mucking about with my .htaccess file, and site.conf files, but I cannot seem to get this working.

For context, I have the following file structure:

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

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

Here is my current .htaccess config:

# 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:

<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.

I've also ensured that mod_rewrite is enabled in Apache, and I have rebooted the server.

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 )

Quoted from 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. Create the new location for the core WordPress files to be stored (we will use /wordpress in our examples). (On linux, use mkdir wordpress from your www directory. You'll probably want to use chown apache:apache on the wordpress directory you created.)

  2. Go to the General Screen.

  3. In WordPress address (URL): set the address of your main WordPress core files. Example: http://example.com/wordpress

  4. In Site address (URL): set root directory's URL. Example: http://example.com

  5. Now move your WordPress core files (from root directory) to the subdirectory.

  6. Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress directory into the root directory of your site (Blog address). The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. If you are not using pretty permalinks, then you may not have a .htaccess file. 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. For the index.php file the instructions remain the same, copy (don't move) the index.php file to your root directory. 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.

  7. Open your root directory's index.php file in a text editor

  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' );

  9. Login to the new location. It might now be 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. 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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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