2

I had a forum with /forum but it has changed to /forums I want to know if there is a single line code which can redirect my old URL to new ones. It is not simple redirection from /forum to /forums The URL after /forum/abc.html are now /forums/abc.html There are some 500000 URL that need to be changed. Could anybody help

For example

example.com/forum/topic/144934-pio-threatened-rti-applicant/ is now example.com/forums/topic/144934-pio-threatened-rti-applicant/

If you see above the change is just 'S' for all the 500000 URLs

I have already tried this

RewriteEngine On
RewriteRule ^forum/(.*)$ /forums/$1 [NC,L]

I am left with permanent redirection only I am trying this way

Redirect 301 /forum/42534-how-know-my-pf-account-no.html /forums/42534-how-know-my-pf-account-no.html
DocRoot
  • 4,297
  • 12
  • 20
  • In what context are these directives? .htaccess? <Directory> container? Server config or <VirtualHost> container? – DocRoot Jun 04 '18 at 01:25

1 Answers1

2
RewriteRule ^forum/(.*)$ /forums/$1 [NC,L]

This is an internal rewrite, not a redirect. You need to add the R flag to make it an external redirect. Otherwise, this should work OK (depending on the context it is being used - you don't actually say). For example:

RewriteRule ^/?forum/(.*)$ /forums/$1 [NC,R=301,L]

And make sure this appears before any conflicting directives. (eg. If it's in .htaccess then this should usually go at the top.)

However, you only need a simple mod_alias Redirect, unless you already have existing mod_rewrite directives (which could result in conflicts). For example:

Redirect 301 /forum /forums

The mod_alias Redirect directive is prefix-matching, copying everything after the match onto the end of the target URL. eg. /forum/foo is redirected to /forums/foo, etc. And only matches whole path segments, so this avoids a redirect loop.

As always, make sure you clear the browser cache before testing and test with 302 (temporary) redirects to avoid caching problems.

DocRoot
  • 4,297
  • 12
  • 20