.htaccess URL Redirect Not Working

#1
I'm not very familiar with LiteSpeed Server as we've always used Apache in the past but I'm trying to learn. Our forums (vbulletin 4) is suffering an issue with duplicate URLs and improper redirects. I'm trying to add redirects in the .htaccess but I just can't seem to make it work. Am I overlooking something or is there a syntax error? Any help would be appreciated.
Incorrect URL:
Code:
https://www.example.com/content/?176-Minnesota-FFL-Dealers
Desired URL:
Code:
https://www.example.com/content/176-minnesota-ffl-dealers.html
.htaccess rule:
Code:
Redirect 302 /content/?176-Minnesota-FFL-Dealers /content/176-minnesota-ffl-dealers.html
 
Last edited by a moderator:

Pong

Administrator
Staff member
#2
Apache rewrite rules are compatible with LSWS. Have you tested your rule with apache? It doesn't sound working with apache either.
"?" will be treated as the query string in your URL.
may try something like this:
https://stackoverflow.com/questions/3457022/mod-rewrite-remove-query-string-from-url

For example, You can try the following in content/.htaccess to see if it works or not.
Code:
  RewriteEngine on
  RewriteCond %{THE_REQUEST} \?176-Minnesota-FFL-Dealers\sHTTP [NC]
  RewriteRule ^ %{REQUEST_URI}176-minnesota-ffl-dealers.html  [L,R,QSD]
 
Last edited by a moderator:
#3
Apache rewrite rules are compatible with LSWS. Have you tested your rule with apache? It doesn't sound working with apache either.
"?" will be treated as the query string in your URL.
may try something like this:
https://stackoverflow.com/questions/3457022/mod-rewrite-remove-query-string-from-url

For example, You can try the following in content/.htaccess to see if it works or not.
Code:
  RewriteEngine on
  RewriteCond %{THE_REQUEST} \?176-Minnesota-FFL-Dealers\sHTTP [NC]
  RewriteRule ^ %{REQUEST_URI}176-minnesota-ffl-dealers.html  [L,R,QSD]
Thank you for your reply. Unfortunately I don't have access to an apache system for testing at this time but I may need to setup a VM later. Your suggestion didn't work for me and I didn't want to add 50+ rules so I tried some regex. From what I understand from apache the following should work but it also doesn't. Can someone let me know if I've messed up the syntax again? Perhaps there a server config issue? I'm open to any suggestions. What I've tried:
Code:
RewriteRule ^(https:\/\/|http:\/\/)(www\.example\.com\/content\/)\?([0-9]*[-a-z,A-Z]*)$ $1$2$3.html [R=302, L]
Code:
Redirect 302 ^(https:\/\/|http:\/\/)(www\.example\.com\/content\/)\?([0-9]*[-a-z,A-Z]*)$ $1$2$3.html
 
Last edited by a moderator:

Pong

Administrator
Staff member
#4
I would suggest you try your rules with apache to make it work firstly, LSWS should work after that.
 
#5
I setup a complete copy of our website in a virtual machine running Windows 10 x64 and WAMPServer x64. I changed the setup to use mariadb but otherwise is a stock apache setup. I removed all of the SEO plugins that were installed in vBulletin as they weren't doing what we wanted anyway. I'm still working on the other rules but I managed to get one rule working in apache but it still doesn't work in Lightspeed.

For this example I need to redirect /content/123-Title.html to /content.php?123-Title
Code:
Redirect 302 ^\/content\/([0-9A-Za-z\-]*)\.html$ http://sub.example.com/content.php?%1
Works in apache, but not Litespeed. When I try to visit the bad URL for testing I get the below error but no entry in the error_log.
Code:
[an error occurred while processing this directive]
 

Pong

Administrator
Staff member
#6
Before we dive into any specific rewrite rules, I want to know what's your issue from a high level and what's the requirements in full? Otherwise, one issue can be fixed. such as your initial question, but more others coming.
As I understand so far, your vbulletin 4 has some URL issue, right? Why did it happen? Have you checked with VBulletin support to fix that URL from database or bulletin backend or PHP code?

If you still want to fix everything in rewrite rules, you can have your full rules ready and be working with Apache, we can tune it to make it work with LiteSpeed.
 
Top