LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > Apache Migration/Compatibility > [solved] Apache Rewrite Rules with RewriteBase not working

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2012, 11:45 AM
thehelpdesk thehelpdesk is offline
Member
 
Join Date: Feb 2011
Posts: 14
Default [solved] Apache Rewrite Rules with RewriteBase not working

We've migrated a client to LSWS 4.1.10 Ent from an Apache environment. The site worked perfectly in Apache but now the ReWrite rules aren't working correctly. Below are the rules in the problematic .htaccess file:

RewriteEngine On
RewriteBase /directory/

RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ index.php?func=$1&urlA=$2&urlB=$3&urlC=$4 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?func=$1&urlA=$2&urlB=$3 [L]
RewriteRule ^([^/]*)/([^/]*)$ index.php?func=$1&urlA=$2 [L]
RewriteRule ^([^/]+)/(.*)$ index.php?func=$1 [QSA,L]

The rewrite engine appears to be working but its not passing variables on to index.php as it should be. We can't seem to figure out how to get it to work in LSWS even though everything works perfectly in Apache.
Reply With Quote
  #2  
Old 01-16-2012, 04:31 PM
webizen webizen is offline
LiteSpeed Staff
 
Join Date: Oct 2010
Posts: 2,338
try this
%
Quote:
RewriteEngine On
RewriteBase /directory/

RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ index.php?func=$1&urlA=$2&urlB=$3&urlC=$4 [QSA,L]
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?func=$1&urlA=$2&urlB=$3 [QSA,L]
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]*)/([^/]*)$ index.php?func=$1&urlA=$2 [QSA,L]
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)/(.*)$ index.php?func=$1 [QSA,L]
Reply With Quote
  #3  
Old 01-17-2012, 01:02 PM
thehelpdesk thehelpdesk is offline
Member
 
Join Date: Feb 2011
Posts: 14
That did not make any difference, same results. We cut-and-pasted the quoted code directly.
Reply With Quote
  #4  
Old 01-17-2012, 01:19 PM
webizen webizen is offline
LiteSpeed Staff
 
Join Date: Oct 2010
Posts: 2,338
make sure 'RewriteBase /directory/' points to the actual directory in question.

also, enable rewrite logging (add 'RewriteLogLevel 9' in httpd.conf) to further troubleshoot the rules (yours and mine).

Last edited by webizen; 01-17-2012 at 01:22 PM..
Reply With Quote
  #5  
Old 01-17-2012, 01:32 PM
thehelpdesk thehelpdesk is offline
Member
 
Join Date: Feb 2011
Posts: 14
The /directory/ folder does actually exist and is the base URL that's getting accessed. We've only changed the names here to protect the client's privacy. In the below log, /consultant/ represents /directory/ above.

The results of RewriteLogLevel 9 are:

Our Rules:
2012-01-17 16:26:12.830 [INFO] [HTAccess] Updating configuration from [/home/domaincom/domains/domain.com/public_html/consultant/.htaccess]
2012-01-17 16:26:12.830 [INFO] [IPADDR:1586-0#APVH_www.domain.com] [REWRITE] strip base: '/consultant/' from URI: '/consultant/find-a-consultant/'
2012-01-17 16:26:12.830 [INFO] [IPADDR:1586-0#APVH_www.domain.com] [REWRITE] Rule: Match 'find-a-consultant/' with pattern '^([^/]*)/([^/]*)/([^/]*)/([^/]*)$', result: -1
2012-01-17 16:26:12.830 [INFO] [IPADDR:1586-0#APVH_www.domain.com] [REWRITE] Rule: Match 'find-a-consultant/' with pattern '^([^/]*)/([^/]*)/([^/]*)$', result: -1
2012-01-17 16:26:12.830 [INFO] [IPADDR:1586-0#APVH_www.domain.com] [REWRITE] Rule: Match 'find-a-consultant/' with pattern '^([^/]*)/([^/]*)$', result: 3
2012-01-17 16:26:12.830 [INFO] [IPADDR:1586-0#APVH_www.domain.com] [REWRITE] Source URI: 'find-a-consultant/' => Result URI: 'index.php?func=find-a-consultant&urlA='
2012-01-17 16:26:12.830 [INFO] [IPADDR:1586-0#APVH_www.domain.com] [REWRITE] replace current query string with 'func=find-a-consultant&urlA='
2012-01-17 16:26:12.830 [INFO] [IPADDR:1586-0#APVH_www.domain.com] [REWRITE] Last Rule, stop!
2012-01-17 16:26:12.830 [INFO] [IPADDR:1586-0#APVH_www.domain.com] [REWRITE] prepend rewrite base: '/consultant/', final URI: '/consultant/index.php'

Your Rules:
2012-01-17 16:29:19.122 [INFO] [HTAccess] Updating configuration from [/home/domaincom/domains/domain.com/public_html/consultant/.htaccess]
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] strip base: '/consultant/' from URI: '/consultant/find-a-consultant/'
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] Rule: Match 'find-a-consultant/' with pattern '^([^/]*)/([^/]*)/([^/]*)/([^/]*)$', result: -1
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] Rule: Match 'find-a-consultant/' with pattern '^([^/]*)/([^/]*)/([^/]*)$', result: -1
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] Rule: Match 'find-a-consultant/' with pattern '^([^/]*)/([^/]*)$', result: 3
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] Cond: Match '/consultant/find-a-consultant/' with pattern 'index.php', result: -1
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] Source URI: 'find-a-consultant/' => Result URI: 'index.php?func=find-a-consultant&urlA='
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] append query string 'func=find-a-consultant&urlA='
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] Last Rule, stop!
2012-01-17 16:29:19.123 [INFO] [IPADDR:1617-0#APVH_www.domain.com] [REWRITE] prepend rewrite base: '/consultant/', final URI: '/consultant/index.php'
Reply With Quote
  #6  
Old 01-17-2012, 03:49 PM
webizen webizen is offline
LiteSpeed Staff
 
Join Date: Oct 2010
Posts: 2,338
so what you want is that if nothing after last "/", do not show that (empty parameter) in query string.

/directory/find-a-consultant/ ==> index.php?func=find-a-consultant instead of index.php?func=find-a-consultant&urlA=

Quote:
RewriteEngine On
RewriteBase /directory/

RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)[/]*$ index.php?func=$1&urlA=$2&urlB=$3&urlC=$4 [QSA,L]
#RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)/([^/]+)/([^/]+)[/]*$ index.php?func=$1&urlA=$2&urlB=$3 [QSA,L]
#RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)/([^/]+)[/]*$ index.php?func=$1&urlA=$2 [QSA,L]
#RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)[/]*$ index.php?func=$1 [QSA,L]
Reply With Quote
  #7  
Old 01-18-2012, 10:20 AM
thehelpdesk thehelpdesk is offline
Member
 
Join Date: Feb 2011
Posts: 14
Anything contained within the first / after the base directory should be passed to the first variable, which goes to func=. Then anything in the next set of slashes goes to urlA, next set to urlB, and next set to urlC. urlA, urlB, and urlB - or their corresponding variables - might be empty.

Right now LSWS seems to only be passing the first variable and not the 2, 3, and 4 variables.
Reply With Quote
  #8  
Old 01-18-2012, 10:31 AM
webizen webizen is offline
LiteSpeed Staff
 
Join Date: Oct 2010
Posts: 2,338
in our lab, test result is like

/directory/abc/def/ghi ==> index.php?func=abc&urlA=def&urlB=ghi

is that your desired result?

Quote:
Right now LSWS seems to only be passing the first variable and not the 2, 3, and 4 variables.
pls show rewritelog.
Reply With Quote
  #9  
Old 01-18-2012, 10:42 AM
thehelpdesk thehelpdesk is offline
Member
 
Join Date: Feb 2011
Posts: 14
Almost:

/directory/abc/def/ghi/ ==> index.php?func=abc&urlA=def&urlB=ghi

Note the last trailing slash after ghi. If it could work both ways that would be great, but, we're just trying to get it to work the one way to start as it does on Apache.
Reply With Quote
  #10  
Old 01-18-2012, 10:49 AM
webizen webizen is offline
LiteSpeed Staff
 
Join Date: Oct 2010
Posts: 2,338
Quote:
Originally Posted by thehelpdesk View Post

/directory/abc/def/ghi/ ==> index.php?func=abc&urlA=def&urlB=ghi
Yes, our lab test shows it works the same way with or without the trailing slash.

/directory/abc/def/ghi(/)* ==> index.php?func=abc&urlA=def&urlB=ghi
Reply With Quote
Reply

Tags
.htaccess, rewrite, rewrite. litespeed

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:10 AM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.