Please help me convert this simple rewrite rule from nginx to Litespeed

#1
We are trying to convert our nginx server to Litespeed, and one of the final pieces I need to solve is rewriting this simple rewrite rule to Litespeed's format

Nginx Rule:
Code:
~^/index\.php\?(?<suffix>(forums|threads|members|resources|posts|help|tags|attachments).*)$ /forum/$suffix;
This redirects URLs like site.com/index.php?forums/test.1234 to site.com/forum/forums/test.1234

It's important that the redirect rule only match those suffixes that are listed in the regex, though. For the life of me, I simply cannot get the Litespeed syntax figured out. Any help would be greatly appreciated.
 
#3
Yes, I know. The problem is that I haven't used Apache in at least 7 or 8 years, so I'm extremely rusty on its syntax. I have tried multiple variations of things I thought should work, and none of them are working. For example, here is my current iteration:

Code:
RewriteRule ^index\.php\?((forums|threads|members|resources|posts|help|tags|attachments).*)$ /forum/$1 [R=301,L]
Believe me, I spent hours trying to figure this out before posting for help.
 
#5
Sorry, I thought I had. It's pretty simple.
Code:
map $request_uri $redirect {
    default 0;
    # Redirects old XF urls in root to new SEO friendly URLs in /forum/
    ~^/index\.php\?(?<suffix>(forums|threads|members|resources|posts|help|tags|attachments).*)$ /forum/$suffix;
    # Lots of other redirect definitions follow.....
}

# Redirect with a 301 if needed
if ($redirect) {
    return 301 $redirect;
}
Basically, we have quite a few redirects, so we added them all to a nginx map and then later in the config, we check to see if $redirect is set, and if it is, we redirect with a 301 to that URL.

So for instance, https://site.com/index.php?forums/name.12 will 301 redirect to https://site.com/forum/forums/name.12 and https://site.com/index.php?threads/thread-title.123 will redirect to https://site.com/forum/threads/thread-title.123

Thanks for any advice you can offer me!
 

NiteWave

Administrator
#6
please try if following will work:
Code:
RewriteCond %{QUERY_STRING} ((forums|threads|members|resources|posts|help|tags|attachments).*)$
RewriteRule index.php /forum/%1 [R=301,L]
 
Last edited:
#7
Thank you! That actually did work! The only problem I have with it is that it catches ALL index.php requests with a matching query string. I specifically need it to only match the root index.php file. I have tried RewriteRule ^index.php, which I thought would work, but it did not. Any advice?

I really appreciate your help!
 

serpent_driver

Well-Known Member
#8
Try this

Code:
RewriteCond %{REQUEST_URI} ^index\.php
RewriteCond %{QUERY_STRING} ((forums|threads|members|resources|posts|help|tags|attachments).*)$
RewriteRule index.php /forum/%1 [R=301,L]
 

serpent_driver

Well-Known Member
#10
If it doesn't work, try this

Code:
RewriteCond %{REQUEST_URI} ^\/index\.php
RewriteCond %{QUERY_STRING} ((forums|threads|members|resources|posts|help|tags|attachments).*)$
RewriteRule index.php /forum/%1 [R=301,L]
 
Top