[Help] Simple Rewrite

#2
Hi slowaways,

The first two lines are not needed.
You will have to put this in the virtual host's rewrite rules.

This can be done via web admin at Virtual Host -> select virtual host -> Rewrite

This can also be done by editing your virtual host's config file:
SERVER_ROOT/conf/vhosts/VH_NAME/vhconf.conf

Code:
rewrite {
  enable 1
  logLevel 0

  rules <<<END_rules
  RewriteCond %{HTTP_USER_AGENT}  ^NameOfBadRobot
  RewriteRule ^/nospider/         -   [F]
  RewriteRule ^ 0.php [L]
  END_rules
}
Then restart the server. If you set the log level to 9, you will be able to test it by visiting a page and going to the error log to see if the server tried comparing the url against the rule.

Let me know how it goes,
Kevin
 
#3
Hi slowaways,

The first two lines are not needed.
You will have to put this in the virtual host's rewrite rules.

This can be done via web admin at Virtual Host -> select virtual host -> Rewrite

This can also be done by editing your virtual host's config file:
SERVER_ROOT/conf/vhosts/VH_NAME/vhconf.conf

Code:
rewrite {
  enable 1
  logLevel 0

  rules <<<END_rules
  RewriteCond %{HTTP_USER_AGENT}  ^NameOfBadRobot
  RewriteRule ^/nospider/         -   [F]
  RewriteRule ^ 0.php [L]
  END_rules
}
Then restart the server. If you set the log level to 9, you will be able to test it by visiting a page and going to the error log to see if the server tried comparing the url against the rule.

Let me know how it goes,
Kevin
Did not work!

error.log
2016-08-18 13:15:39.899 [INFO] [127.0.0.1:34420] [REWRITE] Rule: Match '/' with pattern '^/nospider/', result: -1
2016-08-18 13:15:39.899 [INFO] [127.0.0.1:34420] [REWRITE] Rule: Match '/' with pattern '^', result: 1
2016-08-18 13:15:39.899 [INFO] [127.0.0.1:34420] [REWRITE] Source URI: '/' => Result URI: '0.php'
2016-08-18 13:15:39.900 [INFO] [127.0.0.1:34420] [REWRITE] Last Rule, stop!
2016-08-18 13:15:39.930 [INFO] [127.0.0.1:34422] [REWRITE] Rule: Match '/libs/bootstrap/css/bootstrap.min.css' with pattern '^/nospider/', result: -1
2016-08-18 13:15:39.930 [INFO] [127.0.0.1:34422] [REWRITE] Rule: Match '/libs/bootstrap/css/bootstrap.min.css' with pattern '^', result: 1
2016-08-18 13:15:39.930 [INFO] [127.0.0.1:34422] [REWRITE] Source URI: '/libs/bootstrap/css/bootstrap.min.css' => Result URI: '0.php'
2016-08-18 13:15:39.930 [INFO] [127.0.0.1:34422] [REWRITE] Last Rule, stop!
2016-08-18 13:15:39.934 [INFO] [127.0.0.1:34424] [REWRITE] Rule: Match '/libs/bootstrap-table/bootstrap-table.min.css' with pattern '^/nospider/', result: -1
2016-08-18 13:15:39.934 [INFO] [127.0.0.1:34424] [REWRITE] Rule: Match '/libs/bootstrap-table/bootstrap-table.min.css' with pattern '^', result: 1
2016-08-18 13:15:39.934 [INFO] [127.0.0.1:34426] [REWRITE] Rule: Match '/libs/bootstrap-select/css/bootstrap-select.min.css' with pattern '^/nospider/', result: -1
2016-08-18 13:15:39.934 [INFO] [127.0.0.1:34424] [REWRITE] Source URI: '/libs/bootstrap-table/bootstrap-table.min.css' => Result URI: '0.php'
2016-08-18 13:15:39.934 [INFO] [127.0.0.1:34426] [REWRITE] Rule: Match '/libs/bootstrap-select/css/bootstrap-select.min.css' with pattern '^', result: 1
2016-08-18 13:15:39.934 [INFO] [127.0.0.1:34424] [REWRITE] Last Rule, stop!
...
 
#4
What did you want to do with that rule?

It looks like it's doing what the rule should be doing, it's matching ^ and converting it to 0.php. Did you intend to do something different?
 
#5
I have a project that if i have a file .htaccess in root directory with the following rules:
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^ 0.php [L]
... in the Apache or LiteSpeed Standard Version (with HT Access actived) works fine. The variable $_SERVER['REDIRECT_URL'] is set in PHP, but with this rules for OpenLiteSpeed, $_SERVER['REDIRECT_URL'] is null for any path in url.

Using var_dump($_SERVER['REDIRECT_URL']) in 0.php script that is in the root folder see examples below.

Examples with Apache/LiteSpeed Standard:
localhost/test/
$_SERVER['REDIRECT_URL'] = string (length=5) '/test'

localhost/test/sub
$_SERVER['REDIRECT_URL'] = string (length=9) '/test/sub'​

Examples with Open LiteSpeed Rewrite:
localhost/test/
$_SERVER['REDIRECT_URL'] = null

localhost/test/sub
$_SERVER['REDIRECT_URL'] = null
 
#6
Hi slowaways,

Sorry about such a late response. We have a patch below that should fix this issue.

Kevin

Code:
diff --git src/http/httpcgitool.cpp src/http/httpcgitool.cpp
index 7ce177c..b7b22e6 100644
--- src/http/httpcgitool.cpp
+++ src/http/httpcgitool.cpp
@@ -525,8 +525,30 @@ int HttpCgiTool::buildCommonEnv(IEnv *pEnv, HttpSession *pSession)
         }
         pEnv->add("PATH_INFO", 9, pReq->getPathInfo(), n);
         ++count;
+
+        if (pReq->getRedirects() > 0)
+        {
+            pEnv->add("ORIG_PATH_INFO", 14, pReq->getPathInfo(), n);
+            ++count;
+        }
     }
+    if (pReq->getRedirects() > 0)
+    {
+        pTemp = pReq->getRedirectURL(n);
+        if (pTemp && (n > 0))
+        {
+            pEnv->add("REDIRECT_URL", 12, pTemp, n);
+            ++count;
+        }
+        pTemp = pReq->getRedirectQS(n);
+        if (pTemp && (n > 0))
+        {
+            pEnv->add("REDIRECT_QUERY_STRING", 21, pTemp, n);
+            ++count;
+        }
+    }
+   
     //add geo IP env here
     if (pReq->isGeoIpOn())
     {
diff --git src/http/httpreq.h src/http/httpreq.h
index 5939e40..861a827 100644
--- src/http/httpreq.h
+++ src/http/httpreq.h
@@ -677,6 +677,20 @@ public:
             return m_reqURLLen;
     }
+    const char *getRedirectURL(int &len)
+    {
+        ls_strpair_t &url = (m_iRedirects ? m_pUrls[m_iRedirects - 1] : m_curUrl);
+        len = ls_str_len(&(url.key));
+        return ls_str_cstr(&(url.key));
+    }
+
+    const char *getRedirectQS(int &len)
+    {
+        ls_strpair_t &url = (m_iRedirects ? m_pUrls[m_iRedirects - 1] : m_curUrl);
+        len = ls_str_len(&(url.val));
+        return ls_str_cstr(&(url.val));
+    }
+
     int isMatched() const
     {
         return m_iMatchedLen;
 
#8
Awesome! :)

Eventually, yes. Not sure on the timeline, but I think (things may change) we plan on releasing a new version sometime soon.
 
Top