[Resolved] .htacces passing variable rewrite

Status
Not open for further replies.
#1
Hello,

I'm new in litespeed and still in trial mode to make sure it's working properly with my sites.

I have problem with rewriterule.

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(.*)/(.*)/$ index.php?view=$2 [L]
RewriteRule ^category/(.*).html$ index.php?cat=$1&p=$2 [L]
RewriteRule ^category/(.*)-page-(.*)$ index.php?cat=$1&p=$2 [L]
RewriteRule ^(.*)-(.*).html$ index.php?w=$2
RewriteRule ^page-(.*)$ index.php?p=$1
RewriteRule ^(.*)/(.*).html$ index.php?q=$2 [L]
RewriteRule ^(.*)/(.*)-page-(.*).html$ index.php?q=$2&p=$3 [L]
this part is not working in litespeed if the q variable passing string with space but it work perfectly fine in apache.

Code:
RewriteRule ^(.*)/(.*).html$ index.php?q=$2 [L]
Probably it may have some other solution but I can't think of good one.

thank you.
 

mistwang

LiteSpeed Staff
#2
Please give us an example URL and the expected result.
If I use input URL like "/path/file%20name.html", the rewrite result is
/index.html?q=file name
PHP's
_SERVER["QUERY_STRING"]
value is
q=file name
 
#3
find-me-more is the query string $q

example URL "domain.com/path/find-me-more.html" it's work fine in apache but it return nothing in litespeed.

I tried with different separator using "_" instead "-", its work "domain.com/path/find_me_more.html"
but it will change all URL link(s) in the sites.
 

mistwang

LiteSpeed Staff
#4
There is no problem with "find-me-more", maybe the problem is caused by something else.
You can turn on rewrite debug logging with adding directive

RewriteLogLevel 9

to apache httpd.conf <virtualhost ...> section, then check main error log.

In the PHP code, you can dump out the value of q see if you get the same value from Apache and LiteSpeed.

It is more likely a difference in your PHP setup, please check phpinfo() output from Apache and LiteSpeed, they should be very close to match each other.
 
#5
when trying to dump $q in litespeed it return nothing.

Code:
if ($_GET['q'])
{  
   $q = $_GET['q'];
print ($q);
}
and it's return in apache.

error log show nothing.

when trying index.php?q=find-more-info both work fine, that why I though something wrong with RewriteRule in litespeed

like you said phpinfo it almost match each other,
 

mistwang

LiteSpeed Staff
#6
It is strange behavior of Apache rewrite engine, described in https://issues.apache.org/bugzilla/show_bug.cgi?id=38642
basically,
rewrite rule
RewriteRule ^(.*)-(.*).html$ index.php?w=$2
happens first, Apache rewrite it to /index.php?w=info,
then "add path info postfix" change it to /index.php/find-more-info.html?w=info, which is strange
then
RewriteRule ^(.*)/(.*).html$ index.php?q=$2 [L]
rewrite it to
Code:
/index.php?q=find-more-info
LSWS does not do the "add path info postfix", so the end result is /index.php?w=info

You can get around that by reorder the rule, or modify the first rule to avoid the first matching. like
Code:
RewriteRule^([^/]*)-(.*).html$ index.php?w=$2
 
Last edited by a moderator:
#7
Thank's a Lot mistwang, you rock!!

conclusion for other if the same thing happen:

You cannot have the same RewriteRule Patern in your htaccess with the samew URI base.

e.g
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(.*)/(.*)/$ index.php?view=$2 [L]
RewriteRule ^category/(.*).html$ index.php?cat=$1&p=$2 [L]
RewriteRule ^category/(.*)-page-(.*)$ index.php?cat=$1&p=$2 [L]
RewriteRule ^(.*)-(.*).html$ index.php?w=$2
RewriteRule ^page-(.*)$ index.php?p=$1
RewriteRule ^(.*)/(.*).html$ index.php?q=$2 [L]
RewriteRule ^(.*)/(.*)-page-(.*).html$ index.php?q=$2&p=$3 [L]

there are 2 same rule patern above

Code:
RewriteRule ^(.*)-(.*).html$ index.php?w=$2
RewriteRule ^(.*)/(.*).html$ index.php?q=$2 [L]
use another regex patern with the same result

e.g
Code:
RewriteRule^([^/]*)-(.*).html$ index.php?w=$2
RewriteRule ^(.*)/(.*).html$ index.php?q=$2 [L]
Thank you.
Switching to production license.
 
Status
Not open for further replies.
Top