• Anyone know how to solve this one?

    I’ve got WP in a /blog directory – rather than at the top level of the site.

    I’d like to use the custom-structured permalinks to improve SEO.

    I put this code in the custom structure field to make it work:

    /%category%/%postname%/

    And followed the instructions to add this to the htaccess file:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>

    Everything was working really well, until I noticed that any 404 file-not-found messages on the main site ended up buried in a garbled version of my blog layout.

    I removed the code from the htaccess file and the 404 is now working fine again. But I’d really like to use those custom links.

    Does anyone know of a way around the problem? And advice would be much appreciated.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think I have a similar problem but the link offered above was not helpful.

    I changed my permalink structure to year/month/post instead of ?page_id=.

    I had created a line in the htacces file something like:

    ErrorDocument 404 https://www.chooseamc.com/?page_id=300

    It redirected to a WordPress page I named AMC Sitemap. Worked great.

    After I changed to the new permalink structure, the 404 redirect in the htaccess file no longer worked. So I changed it to the new permalink:

    ErrorDocument 404 https://www.chooseamc.com/amc-sitemap/

    Now WordPress just goes straight to it’s default 404 in my themes file and ignores this command in my htaccess.

    Is there something else I need to do?

    Ok, there could be a few solutions to the problem. First is assuming you know how to use Media Library and correctly link to a file and your still getting the error my hunch is that it’s the .htaccess file. If not and your a real novice try this: https://www.youtube.com/watch?v=XJFIbd6wN0A&feature=related

    Also, see my post re this issue: https://www.ads-software.com/support/topic/357445?replies=10

    For me, the problem was related to permalinks and the .htaccess file which was calling for a 404 error page instead of accessing the file. So wordpress — or at least a faulty .htaccess — was effectively “blocking” access to files. After a long talk with tech support at the site host, and looking through error logs, trying a few things here and there, we determined it was indeed the .htaccess file.

    So I deleted the .htaccess file after removing permalink settings and the files loaded. But this caused a few other issues with pages not being found etc. So rewrote the .htaccess file (see below).

    Plus, the .htaccess file is what’s responsible for generating the 404 error page in the first place which I didn’t know and would have helped me narrow down the problem in the first place. Here’s a good link re .htaccess: https://www.freewebmasterhelp.com/tutorials/htaccess/

    So here, from the codex, I think is the root of the problem:

    Using only %postname%

    If using version 2.0 or greater, the following is no longer true as this has been changed.

    If you use postname as the only element in your permalinks to create a structure such as example.com/post-title, the rewrite rules may make it impossible to access pages such as your stylesheet (which has a similar format) or the /wp-admin/ folder . It’s best to include some numeric data (e.g. the post ID or date) in the permalink to prevent this from happening. Additionally, WordPress v1.2.x requires the use of a date structure in order for some features, such as the calendar, to function properly. /%year%/%monthnum%/%day%/%postname%/ is always a good start.

    You can get past the above issue and continue using %postname% if you make a simple change to your .htaccess file as below:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} ^wp-content.*
    RewriteCond %{REQUEST_FILENAME} ^wp-admin.*
    RewriteCond %{REQUEST_FILENAME} ^wp-include.*
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Simply the conditions now say do not apply the rule if the file name includes the word press content, admin or include directory. This now allows you to get to the admin area with no issues as well as content.

    Which is from the codex here: https://codex.www.ads-software.com/Using_Permalinks And don’t say ” Should’ve read the codex first”, because I would have if I could have isolated the problem to the .htaccess file initially.

    Thing is, my .htaccess file didn’t include the #BEGIN and #END WordPress. Which is my best guess as to why it was preventing access to files uploaded with Media Library.

    If you haven’t changed your permalinks settings it’s possible something else has tinkered with your .htaccess file and it’s the same problem. So I would try rewriting it anyway. And change the permissions to 666 so wordpress can write to it afterward.

    I found a few of the images were still not working so I had to go back and reload them with media library. It worked.

    So I hoped that helps anyone else who seems to be having this problem.

    I look forward to any feedback on this issue, e.g. why exactly is it that using only /%postname%/ as your permalink structure restricts access to some files????

    Anyway all the best, keep up the good work wordpress team!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom permalinks and 404 problem’ is closed to new replies.