Jeremie
Jeremie

Reputation: 25

.htaccess redirect according to PHP parameters and general case

On this other topic : .htaccess redirect according to PHP parameters I got help to make redirections according to some PHP parameters, for instance, like

/forum/viewtopic.php?t=123 redirected to /page1.html
/forum/viewtopic.php?t=345 redirected to /page7.html
/forum/viewtopic.php?t=89 redirected to page3.html

The (working) solution proposed is

RewriteEngine On
RewriteCond %{QUERY_STRING} ^t=123$
RewriteRule ^forum/viewtopic\.php$ /page1.html? [L,R=301]

RewriteCond %{QUERY_STRING} ^t=345$
RewriteRule ^forum/viewtopic\.php$ /page7.html? [L,R=301]

RewriteCond %{QUERY_STRING} ^t=89$
RewriteRule ^forum/viewtopic\.php$ /page3.html? [L,R=301]

I would like to add a "general" case at the end: if no URL matched, and the folder "/forum" is asked, redirect to the root. For instance

/forum redirected to /
/forum/viewtopic.php?t=34598237 redirected to /
/forum/something redirected to /

How can I do that ?

Upvotes: 1

Views: 44

Answers (1)

martynasma
martynasma

Reputation: 8595

Just add this line at he end:

RewriteRule ^forum / [L,R=301]

Since all of your previous conditions had [L] modifier (which instructs any further rules processing), this last condition would only kick in only if any of the previous ones does not match.

Upvotes: 1

Related Questions