Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted January 21, 20232 yr 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>
January 22, 20232 yr Community Expert 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, 20232 yr by Randy Calvert
January 22, 20232 yr Author Sorry - it didn't work. Need from: https://site.com/forums/files/file/38-silent/ TO: https://site.com/files/file/38-silent/
January 22, 20232 yr Community Expert 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.
January 22, 20232 yr Author 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>
January 22, 20232 yr Author 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>
January 22, 20232 yr Community Expert 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.