[Resolved] Rewrite Bases issue with PHPIPAM [FIXED: User ERROR]

Status
Not open for further replies.
#1
Hi Guys,

Sorry to bother you but I am having an issue with configuring a web application which I usully use Apache with and I wondered if someone could point the issue out to me.

The name of the software is PHPIPAM and can be obtained from here http://phpipam.net/documents/download-phpipam/

It uses a .htaccess file file to setup some rewrite rules and one of them is the RewriteBase rule.

After adding the rewrite rules into the OLS Admin Panel that it seems to ignore them (at least the RewriteBase rule anyway).

I have since tried to create a static context with the below rewrite code which should work but alais it seems to not be doing anything and yes its enabled.

Code:
RewriteEngine on

# change rewrite base if not in root
RewriteBase /ipam

# passthroughs
RewriteRule ^api/.$ - [L]
RewriteRule ^index.php$ - [L]
RewriteRule ^(css|js|site|test)/.*$ - [L]
RewriteRule site/login/captcha/captchashow.php - [L]

# redirect errors
ErrorDocument 400 /error/400/
ErrorDocument 401 /error/401/
ErrorDocument 403 /error/403/
ErrorDocument 404 /error/404/
ErrorDocument 500 /error/500/

# IE login dashboard fix
RewriteRule ^login/dashboard/$ dashboard/ [R]
RewriteRule ^logout/dashboard/$ dashboard/ [R]
# search override
RewriteRule ^tools/search/(.*)/(.*)/(.*)/(.*)/(.*)$ index.php?page=tools&section=search&addresses=$1&subnets=$2&vlans=$3&vrf=$4&ip=$5 [L]

# Rewrites
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ index.php?page=$1&section=$2&subnetId=$3&sPage=$4&ipaddrid=$5 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ index.php?page=$1&section=$2&subnetId=$3&sPage=$4 [L]
RewriteRule ^(.*)/(.*)/(.*)/$ index.php?page=$1&section=$2&subnetId=$3 [L]
RewriteRule ^(.*)/(.*)/$ index.php?page=$1&section=$2 [L]
RewriteRule ^(.*)/$ index.php?page=$1 [L]
Heres the snipet from the vhost config file of OLS, as you can see I moved the RewriteBase to the section in the portel and rest of the code below, which AFAIK should work. Any ideas?

Code:
context /ipam/ {
  type                    NULL
  location                /ipam/
  allowBrowse             1

  rewrite  {
    enable                1
    base                  /ipam/
    rules                 <<<END_rules
RewriteEngine on

# passthroughs
RewriteRule ^api/.$ - [L]
RewriteRule ^index.php$ - [L]
RewriteRule ^(css|js|site|test)/.*$ - [L]
RewriteRule site/login/captcha/captchashow.php - [L]

# redirect errors
ErrorDocument 400 /error/400/
ErrorDocument 401 /error/401/
ErrorDocument 403 /error/403/
ErrorDocument 404 /error/404/
ErrorDocument 500 /error/500/

# IE login dashboard fix
RewriteRule ^login/dashboard/$ dashboard/ [R]
RewriteRule ^logout/dashboard/$ dashboard/ [R]
# search override
RewriteRule ^tools/search/(.*)/(.*)/(.*)/(.*)/(.*)$ index.php?page=tools&section=search&addresses=$1&subnets=$2&vlans=$3&vrf=$4&ip=$5 [L]

# Rewrites
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ index.php?page=$1&section=$2&subnetId=$3&sPage=$4&ipaddrid=$5 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ index.php?page=$1&section=$2&subnetId=$3&sPage=$4 [L]
RewriteRule ^(.*)/(.*)/(.*)/$ index.php?page=$1&section=$2&subnetId=$3 [L]
RewriteRule ^(.*)/(.*)/$ index.php?page=$1&section=$2 [L]
RewriteRule ^(.*)/$ index.php?page=$1 [L]
    END_rules

  }
  addDefaultCharset       off
}
Can anyone give me a hint on what I am doing wrong? Thank you.
 
Last edited:
L

Long

Guest
#2
Hi,
Which version of OLS are you working with?
Before testing your case, can you verify whether the rewrite is working with a simpler test case?
Please make sure rewrite is enabled and .htaccess is enabled and allowoverride set properly.
This way we can isolate the issue to a further step.
 
#3
Hi there,

Thanks for the reply.

I am using the latest version of OLS which is..

Litespeed Web Server Open 1.4.16

I can confirm that rewrite is also enabled/on.. which also can be seen in the original snipet of OLS config.

Rewrite Control
Enable Rewrite Yes
Log Level 9

In the context its also enabled.

Enable RewriteYes

I have tried just doing a simple RewriteBase rule and use curl to test if its wokring and it doesnt seem to be.

I can also confirm that the rules work fine on my managment (apache) web server. Right now I was just testing/dev running it under litespeed as I am planning to convert all the apache servers and nginx ones over to litespeed and bumpted into this issue which will not only just affect this peace of software but also several others which relies on RewriteBase function.

I have also tried to remove the comments from the rules as well as just try and change the base and use curl to test if the location changes and it doesn't.

Please let me know if theres anything else you require.

Thanks.
 
L

Long

Guest
#4
Hi,

For your reference, I just tested it with a simple case and it is working:
Code:
context /ipam/ {
  type                    NULL
  location                /opt/html/ipam2/
  allowBrowse             1

  rewrite  {
    enable                1
    inherit               1
    base                  /ipam/
    rules                 RewriteRule ^index.html$ 8bytes.html [L]
  }
  addDefaultCharset       off
}
If I enter
Code:
http://hostsite.com/ipam/index.html
it will be redirected to $DOC_ROOT/ipam2/8bytes.html

Maybe you have to check the settings in the static context page and make sure everything is as you expected.

Looks like the location setting needs to be changed in your settings.
 
Last edited by a moderator:
#5
Hi,

For your reference, I just tested it with a simple case and it is working:

Code:
context /ipam/ {
  type                    NULL
  location                /opt/html/ipam2/
  allowBrowse             1

  rewrite  {
    enable                1
    inherit               1
    base                  /ipam/
    rules                 RewriteRule ^index.html$ 8bytes.html [L]
  }
  addDefaultCharset       off
}
If I enter
Code:
http://hostsite.com/ipam/index.html
it will be redirected to $DOC_ROOT/ipam2/8bytes.html

Maybe you have to check the settings in the static context page and make sure everything is as you expected.

Looks like the location setting needs to be changed in your settings.
Hum that is strange, thank you. I will tripple check now as there maybe something else stopping it.

Thank you for testing and sorry for the noise. I will investigate further and report back tomorrow or so depening how busy work is.
 
Last edited by a moderator:
#6
Just had a quick look and ive tried what you done and it seems to rewrite the file however, what it doesnt seem to do is still change the location.

Ive tripple checked it and this is what I see..

Code:
HTTP/1.1 302 Found
Set-Cookie: phpipam=e9l8u0f64fi055h4q0355ioat3; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: phpipamredirect=%2Fipam%2F; expires=Mon, 25-Apr-2016 20:45:04 GMT; Max-Age=10; path=/
Location: http://dev.example.co.uk/?page=login
Content-Type: text/html; charset=UTF-8
Date: Mon, 25 Apr 2016 20:44:54 GMT
Server: LiteSpeed
Connection: Keep-Alive
Now heres what I get when I do it on the management server (LIVE machine running Apache)

Code:
HTTP/1.1 302 Moved Temporarily
Date: Mon, 25 Apr 2016 20:51:35 GMT
Server: Apache
X-Powered-By: PHP/5.4.45-0+deb7u1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=1mq0gpo2jkvqrfo3t366geh3g5; path=/
Location: http://manage.example.co.uk/ipam/login/
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: sameorigin
Vary: Accept-Encoding
Content-Type: text/html
Note the Location. This is what I expect on the second one.. i.e. adds /ipam into the url.

The URL which was used was
Code:
http://manage.example.co.uk/ipam
and also
Code:
http://dev.example.co.uk/ipam
I have even removed some test code (was using some headers to see if it was working or not just to see if it was a compatiablity issue but its still doing it.

Any more ideas?

All I need it to do is redirect / to /ipam henece the baseurl rewrite.
 
Last edited by a moderator:
L

Long

Guest
#7
Hi,
To further debug this issue, you can check from the debug log corresponding to this.
Go to Server Configuration -> Log, in Server Log section, set Log level to DEBUG, Debug level to High.
Restart server and monitor the output with the following the command:
Code:
tail -f /usr/local/lsws/logs/erro.log
You will see how the rewrite rule was processed.

From the rewrite rule you provided above,
Code:
http://dev.example.co.uk/ipam
shouldn't be rewritten to
Code:
http://dev.example.co.uk/?page=login
Looks like there should be somewhere else you got extra steps to process it.
 
Last edited by a moderator:
#8
Thanks for the speedy reply.

There is usually this in there..
Code:
# change rewrite base if not in root
RewriteBase /ipam
In the .htaccess file which is the only thing you usully have to change but I assumed the RewriteBase was done in the box just above the rewrite rules.

Am I wrong? does this also need to be in the actual rewrite rules as well? starts to look confused :)

With regards to logs, I already put the rewrite error to 9 which gave this..

Code:
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] strip base: '/ipam/' from URI: '/ipam/'
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^api/.$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^index.php$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^(css|js|site|test)/.*$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern 'site/login/captcha/captchashow.php', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^login/dashboard/$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^logout/dashboard/$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^tools/search/(.*)/(.*)/(.*)/(.*)/(.*)$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^(.*)/(.*)/(.*)/(.*)/(.*)/$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^(.*)/(.*)/(.*)/(.*)/$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^(.*)/(.*)/(.*)/$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^(.*)/(.*)/$', result: -1
2016-04-25 22:22:46.972 [INFO] [5.9.17.3:53192] [REWRITE] Rule: Match '' with pattern '^(.*)/$', result: -1
p.s. IP been obfuscated.
 
Last edited by a moderator:
#9
OMG, I am so so so so so so so so sorry.

Its been a long time since I set this up (many years) on the IPAM install and I forgot to adjust a value in the config file which you also need to set.

I have just done this and with the usual rewrite rules, its working correctly from what I can see (just going to do install and test but looks fine now)

Again I am so so so sorry for watsing your time. Was my fault. Really sorry and thanks again for pointing it out.

Below is the FIX. Again, so sorry, overlooked it, from memory the installer set everything up but you needed to adjust part of the config file if your running in a subdir which I forgot to do. I assumed and took it out on OLS, again im really sorry.

Code:
**
*      BASE definition if phpipam
*      is not in root directory (e.g. /phpipam/)
*
*  Also change
*      RewriteBase / in .htaccess
******************************/
if(!defined('BASE'))
define('BASE', "/ipam/");
 
Last edited:
Status
Not open for further replies.
Top