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
  • In what context are these directives? .htaccess? <Directory> container? Server config or <VirtualHost> container? – DocRoot Jun 4 '18 at 1:25
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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.