• Resolved lom209

    (@lom209)


    Hey All,

    I’ve been going in circles & circles attempting to fix the issue for a couple of days…Thought it would be best to post here and hope somebody else has experience this issue previously…

    I believe that when I curl / access http://wordpress.local/wp-json/ that I should get something back:

    me0w@wordpressdev:~$ curl http://wordpress.local/wp-json/
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>404 Not Found</title>
    </head><body>
    <h1>Not Found</h1>
    <p>The requested URL was not found on this server.</p>
    <hr>
    <address>Apache/2.4.52 (Ubuntu) Server at wordpress.local Port 80</address>
    </body></html>
    
    
    me0w@wordpressdev:~$ curl http://wordpress.local/wp-json/posts
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>404 Not Found</title>
    </head><body>
    <h1>Not Found</h1>
    <p>The requested URL was not found on this server.</p>
    <hr>
    <address>Apache/2.4.52 (Ubuntu) Server at wordpress.local Port 80</address>
    </body></html>
    

    I have a local WordPress development environment:

    • PHP v7.4
    • WordPress 6.3.1
    • Apache2 Web Server

    Apache Configuration (/etc/apache2/sites-available/wordpress-local.conf):

    <VirtualHost *:80>
        ServerAdmin webmaster@your_domain
        DocumentRoot /var/www/html/
        ServerName wordpress.local
        ServerAlias www.wordpress.local
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

    .htaccess file:

    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    Mod rewrite is enabled:

    me0w@wordpressdev:~$ sudo a2query -m rewrite
    rewrite (enabled by site administrator)
    me0w@wordpressdev:~$ sudo a2enmod rewrite
    Module rewrite already enabled

    My site-url & home url in the WordPress DB are as expected:

    mysql> SELECT * FROM wp_options WHERE option_name = 'siteurl';
    +-----------+-------------+------------------------+----------+
    | option_id | option_name | option_value           | autoload |
    +-----------+-------------+------------------------+----------+
    |         1 | siteurl     | http://wordpress.local | yes      |
    +-----------+-------------+------------------------+----------+
    1 row in set (0.01 sec)
    
    mysql> SELECT * FROM wp_options WHERE option_name = 'home';
    +-----------+-------------+------------------------+----------+
    | option_id | option_name | option_value           | autoload |
    +-----------+-------------+------------------------+----------+
    |         2 | home        | http://wordpress.local | yes      |
    +-----------+-------------+------------------------+----------+
    1 row in set (0.00 sec)

    I also have an entry in my /etc/hosts file for wordpress.local:

    127.0.0.1	wordpress.local

    This is a fresh WordPress installation, so there shouldn’t be any other plugins / themes interfering with the REST API.

    I have tried to ‘Flush Rewrites’ by Saving Changes on Permalink structure without any changes…It’s currently set to Post name

    Any help would be greatly appreciated!

    Thanks

    Lom

    • This topic was modified 1 year, 2 months ago by lom209.
Viewing 3 replies - 1 through 3 (of 3 total)
  • This is usually a sign that permalinks isn’t working on your site.

    Yes, I read your entire post about your config… but I didn’t see any confirmation that permalinks are working as configured.

    Did you actually confirm permalinks is working? Did you open any post/page (other than the homepage, which doesn’t need permalinks) to confirm it’s actually working?

    Thread Starter lom209

    (@lom209)

    Hi @gappiah I feel silly even writing this (I’m testing / expanding the functionality of a plug-in that is only ever accessed within wp-admin so hadn’t taken any notice of the frontend aspect) – I’ve just realised that http://wordpress.local takes me to the apache2 default homepage, as opposed to the WordPress frontend it should be..

    Thanks for the comment…now to try and figure out why the frontend of the site isn’t appearing…

    EDIT: I removed the index.html that Apache2 generates and now http://wordpress.local takes me to the default WordPress homepage for my site…Good news.

    It looks as though you’re correct since if I try to view a post from the wp-admin dashboard, I retrieve a 404

    • This reply was modified 1 year, 2 months ago by lom209.
    Thread Starter lom209

    (@lom209)

    Seems I can’t edit my previous post again…however RESOLVED 🙂

    Added this to my Apache config:

        <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

    We in business, baby.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WP REST API returning 404’s’ is closed to new replies.