0

I need to "internally rewrite" (without any visual redirection) all URLs from an existing folder (and everything inside of it) to its index.php file, similar as what Wordpress does, the problem is, no matter what I try it, either Wordpress overrides it showing their 404 Error page, or the site breaks.

For example, rewrite all of this URLs:

https://www.example.com/folder
https://www.example.com/folder/
https://www.example.com/folder/text
https://www.example.com/folder/text/
https://www.example.com/folder/some/text
https://www.example.com/folder/some/text/
https://www.example.com/folder/some/more/text/......

Basically anything inside /folder/ or any subfolder (whether exist or not) should be internally rewrite to https://www.example.com/folder/index.php and keeping the actual Wordpress working as usual.

I've tried some examples from other sites, as well as from similar questions like: How does RewriteBase work in .htaccess Redirect all to index.php using htaccess .htaccess mod_rewrite - how to exclude directory from rewrite rule

The last one, is because I thought I could exclude the whole /folder/ path from Wordpress rewrites and create an .htaccess file inside that folder to manage it that way, well, Wordpress still shows its 404 error page.

Note: "folder" is a real folder inside the root domain, so is the main .htaccess file, and the Wordpress itself. This folder contains an index.php file.

This is the original Wordpress .htaccess file as shown here:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

I hope someone can help me out, thank you.

Minion
  • 2,497
  • 4
  • 27
  • 29
  • Doesn’t sound that complicated, you just need to do this, before the WP routing can do its thing. It would leave requests for your physically existing `/folder/` alone already - but once you go and request `/folder/does-not-exist`, that would otherwise get caught in the default WP rewriting again. – 04FS Feb 03 '20 at 13:42
  • Hi, I've tried a lot of things, even adding a `` section before Wordpress', still not working, somehow Wordpress keeps showing up its error page, what actually works (obviously) is accessing the real path `/folder/` directly, but no matter what I add after that, Wordpress shows its 404 error page, which brings me the problem, I've tried a bunch of codes from this site from other similar questions, nothing works. – Minion Feb 03 '20 at 13:54
  • You should really rather show us what you actually tried, instead of just vaguely mentioning that you tried “lots of things”. // Try this at the beginning of the file, line breaks between each: `RewriteEngine On`, `RewriteRule ^folder/index\.php$ - [L]`, `RewriteRule ^folder/.+ /folder/index.php [L]` - first rule to not rewrite again if `folder/index.php` is already what was requested, second rule to rewrite every request for `folder/` followed by _anything_ to the index file of the folder. ` – 04FS Feb 03 '20 at 14:02

0 Answers0