I would like every request
example.com/foo/anything
to be rewritten into example.com/foo-anything
before being processed by Wordpress.
I tried this:
RewriteEngine On
RewriteRule ^foo/(.*) foo-$1 # <-- does not work because the subs. string should be a *file path*
# The following is set by Wordpress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
but it does not work because the substitution (destination) string is supposed to be a file path, not another URL.
How to make such a RewriteRule for which the substitution string is not a file path, but an URL, that should be processed by next rules?
Notes:
With
RewriteRule ^foo/(.*) foo-$1 [R]
, it works but then it causes a browser redirection and the URL changes in the URL bar of the browser, which I don't want.I tried with RewriteRule flag
[PT]
which should work even when the substitution string is not a file path, but it did not work for me: it does not redirect/foo/anything
to page/foo-anything
.I tried
RewriteRule ^foo/(.*) index.php?name=foo-$1 [L]
but then it only works for articles, but not pages. I would like a solution working for both pages and articles.