I really need your help with this one…
I’m simply trying to redirect EVERYTHING in a directory to another. It looks simple when I read about it, but in real life, it’s not working… Here is my entire .htaccess file right now:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Redirect all to HTTPS
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.org/$1 [R]
# End redirect
#301 REDIRECTS
Options +FollowSymLinks
RewriteRule ^mydir/(.*)$ /mydir-and-more/$1 [R=301,NC,L]
- Fisrt, there is WordPress stuff in didn’t mess with.
- Then, the code i copy/pasted from some site to redirect http to https. It works well. Note that i removed the “L” argument from the list to make sure my next rules will work.
- After comes the part I’m strugling with.
So, it really is like that. My new directory starts with the same word then my old directory.
I copied this line from there: https://coolestguidesontheplanet.com/redirecting-a-web-folder-directory-to-another-in-htaccess/
On the Apache web site (https://httpd.apache.org/docs/current/mod/mod_rewrite.html) it says that i should use a / between ^ and mydir. Tried it, didn’t work.
I tried moving Options +FollowSymLinks at the top of the file. Nothing.
When i use something like this:
RedirectMatch 301 ^/mydir/ https://example.org/mydir-and-more/
This works. But only moves the exact /mydir/ address. It doesn’t move the whole directory. Also, if I type in https://example.org/mydir without the last /, it won’t work. If i add the / in the Redirect match, it doesn’t work anymore because its the same word!
So, here I am, totally confused! Please, any expert advise on this one? Thanks!!
2
Answers
Funniest thing is, I solved my problem by fooling around! I didn't really need the RewriteRule, all I needed to write instead of the RewriteRule was exactly this :
I don't even need the Options +FollowSymLinks.
You need to move you rules before the wordpress defined ones.
In fact if you try to access you site the rewrite rules elaboration stops at
That instruction means “manage all paths that are not already beign managed by upper rule and stop elaboration ([L] stands for last)”.
You can safely place your rules above the wordpress ones, better in a ifmodule