Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
AlexJ Posted January 21, 2023 Posted January 21, 2023 Moving the site from 'forums' folder to root folder. Can anyone help with htaccess 301 redirect, so old index content by google doesn't get mess up? Thank you. This is the current htaccess: <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map|webp)(\?|$) /404error.php [L,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Randy Calvert Posted January 22, 2023 Posted January 22, 2023 (edited) Try something like: RewriteRule ^/forums/(.*)$ /$1 [L,NC,R=302] But that will only work if forums is not in the new path as well. Edited January 22, 2023 by Randy Calvert
AlexJ Posted January 22, 2023 Author Posted January 22, 2023 Sorry - it didn't work. Need from: https://site.com/forums/files/file/38-silent/ TO: https://site.com/files/file/38-silent/
Randy Calvert Posted January 22, 2023 Posted January 22, 2023 Try that rule without the first slash BUT right after the rewrite engine on directive. I think you’re hitting an order of operations issue.
AlexJ Posted January 22, 2023 Author Posted January 22, 2023 4 minutes ago, Randy Calvert said: Try that rule without the first slash BUT right after the rewrite engine on directive. I think you’re hitting an order of operations issue. Sorry, I don't want to screw up.. so checking. Something like this? <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map|webp)(\?|$) /404error.php [L,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^forums/(.*)$ /$1 [L,NC,R=302] RewriteRule . /index.php [L] </IfModule>
AlexJ Posted January 22, 2023 Author Posted January 22, 2023 Thanks! This worked. Appreciate your help. <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteBase / RewriteRule ^forums/(.*)$ /$1 [L,NC,R=302] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map|webp)(\?|$) /404error.php [L,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Randy Calvert Posted January 22, 2023 Posted January 22, 2023 Just to explain what was going on with the rule, it had to be moved up in the order of operations before later matches routed the request to index.php. The L directive said stop processing rules and just submit as is. The subsequent request with the folder removed then matched the call to index.php. AlexJ 1
Recommended Posts