A few wks back, I was looking for the regex in .htaccess to replace “.htm” in a URL with a trailing slash. With that figured out, everything seemed great. Now, though, I need to create an exception.
If it’s not possible to check for that condition, I’d be willing to compromise by checking for a string in the directories leading to “.htm”. If there is “/admin/editor/” in the URL, don’t touch it, but if it’s anything else, feel free to mess with it.
This is my existing simple trailing slash-.htm swap:
Of course if you want to exclude more directories, just add more RewriteCond’s in the same fashion as the one above.
To come back to the query string, the RewriteRule cannot check the query string, so if you’re not checking by the path the html is in, you have to use RewriteCond.
PS. If your files don’t contain any other dots than the dot in .html, change (.+) to ([^.]+). (.+) is greedy and will eat everything it sees, and that oftentimes causes problems. ([^.]+) will match anything except for a literal dot character, thus it also stops when it finds the . in .html
The ([^.]+) is also slightly less expensive for the regex engine.
Thank you Scallio. I’ve got it to work, it was a pain in the ass, but I remembered to escape the fwd slashes and add the [L,R=301] after some solid troubleshooting. Your teaching style is both non-handicapping, enlightening, and just enough guidance so I can learn to think in the right way to get it done. I appreciate it.
Hold on, did I write that!? Must’ve been tired :x. The ^ and ! are supposed to go the other way around.
Also, do you have variants of the /wp-includes/js/tinymce/themes/advanced directory where some of the letters are capitals instead of lower case, like /WP-includes/JS/TinyMce/Themes/Advanced ?
If you don’t, ditch the [NC]