Change of File Structure and Redirect Issues

Current folder/fie structure:
domainname.com/blog/2019/june/this-is-one-blog-title/

The URL to the blog post would be domainname.com/blog/2019/june/this-is-one-blog-title/index.html, but we are using an .htaccess Rewrite Condition/Rule to remove the “index.html” as well as updated the meta canonical structure in the <head>.

What I need:
domainname.com/blog/this-is-one-blog-title/

However, when I moved the ‘index.html’ to domainname.com/blog/this-is-one-blog-title/ and renamed that file to “this-is-one-blog-title.html”, I get an Error 404 when I test it.

This doesn’t seem logical to get an Error 404 if I moved the file to a different location, renamed it and changed the URL access. It should be appearing. Make sense?

The only thing I can think of is there’s something wrong with my Rewrite/Condition Rules. I don’t want any trailing “index.html” or “index.php”, and the below code does the job, but I’m wondering if it’s affecting my attempts to load the new file structure:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?]*/)?index(\.php|\.html)?(\?.*)?\ HTTP/
RewriteRule .? /%1 [R=301,L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?]*)\.(php|html)(\?.*)?\ HTTP/
RewriteRule .? /%1 [R=301,L,QSA]

Thank you for your time.

Forewarning: I’m not an expert in these things, so I may be entirely wrong.

Your second rule says:
For any request containing .php or .html (that wasnt index.php/html), send them to the same address without the extension.

Which would send http://domainname.com/blog//this-is-one-blog-title/this-is-one-blog-title.html to http://domainname.com/blog/this-is-one-blog-title/this-is-one-blog-title. Which is a directory that doesnt exist…

(Edited because your fetch is different than I had originally posted. I think.)

I’ve managed to just move the blog directories around and created a Redirect 301 to the new folder structure.

Thank you for the reply, m_hutley.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.