markjohnson Posted January 25, 2010 Share Posted January 25, 2010 Hi, I have the following in my .htaccess file: Code: php_flag magic_quotes_gpc off Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-s RewriteRule ^admin(.*)$ admin/index.php [L] RewriteCond %{REQUEST_FILENAME} !-s RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [L,QSA] The idea is to fetch the entire URL into index.php, e.g. http://site.com/page1/page2/3928 index.php would then explode the uri 'page1/page2/3928' into three parts page1/page2 list all the products (i.e. if $uri[2] is not set, then list all products). This works fine. page1/page2/3928 is supposed to present product detail, which it does, but for some reason it also runs the query for product listing (page1/page2) not only once but several times. When I click on page1/page2/3928, mysqyl shows me several instances of product listing query which shouldn't be running at all. My guess is that /page1/page2/3928 is also internally redirecting about 10 times to /page1 as well. The rewrite log file show many instances of the following: Code: 127.0.0.1 - - [25/Jan/2010:02:44:58 +0000] [site/sid#1656600][rid#28e14c8/initial] (2) [perdir C:/xampp/htdocs/site/public_html/] trying to replace prefix C:/xampp/htdocs/site/public_html/ with / 127.0.0.1 - - [25/Jan/2010:02:44:58 +0000] [site/sid#1656600][rid#28e14c8/initial] (1) [perdir C:/xampp/htdocs/site/public_html/] internal redirect with /index.php [iNTERNAL REDIRECT] 127.0.0.1 - - [25/Jan/2010:02:44:58 +0000] [site/sid#1656600][rid#2c53088/initial/redir#1] (3) [perdir C:/xampp/htdocs/site/public_html/] strip per-dir prefix: C:/xampp/htdocs/site/public_html/index.php -> index.php 127.0.0.1 - - [25/Jan/2010:02:44:58 +0000] [site/sid#1656600][rid#2c53088/initial/redir#1] (3) [perdir C:/xampp/htdocs/site/public_html/] applying pattern '(.*)' to uri 'index.php' 127.0.0.1 - - [25/Jan/2010:02:44:58 +0000] [site/sid#1656600][rid#2c53088/initial/redir#1] (3) [perdir C:/xampp/htdocs/site/public_html/] strip per-dir prefix: C:/xampp/htdocs/site/public_html/index.php -> index.php 127.0.0.1 - - [25/Jan/2010:02:44:58 +0000] [site/sid#1656600][rid#2c53088/initial/redir#1] (3) [perdir C:/xampp/htdocs/site/public_html/] applying pattern '^(.+)$' to uri 'index.php' 127.0.0.1 - - [25/Jan/2010:02:44:58 +0000] [site/sid#1656600][rid#2c53088/initial/redir#1] (1) [perdir C:/xampp/htdocs/site/public_html/] pass through C:/xampp/htdocs/site/public_html/index.php Any help will be appreciated. Many thanks! Link to comment https://forums.phpfreaks.com/topic/189718-htaccess-internal-redirects-problem-cpu-load/ Share on other sites More sharing options...
markjohnson Posted January 25, 2010 Author Share Posted January 25, 2010 *bump* For further clarification, here are the two queries, only one of which should run: // This function looks at the uri "/whatever-product-name-id-2039" and extracts the id at the end: 2039 product_id($uri[1]); // Run only if end of uri is a number if (product_id($uri[1])) { //this runs fine, which it should. $qryDisplayProduct = "SELECT * FROM content WHERE id = ".content_id($path[1]); } else { //for some reason, mysql shows several processes for this query which should NOT run. Not only it runs but several instances clogging up the CPU. $qryListProducts = "SELECT * FROM content ORDER BY `date` DESC"; } In light of the above from ReWriteLog, am I right in at least assuming that this is due to internal redirects? What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/189718-htaccess-internal-redirects-problem-cpu-load/#findComment-1001334 Share on other sites More sharing options...
markjohnson Posted January 26, 2010 Author Share Posted January 26, 2010 For further info on the problem: This is what index.php does right in the beginning: $uri = preg_replace("/\/+/", "/", substr($_SERVER["REQUEST_URI"], strlen($cms_path))); if(substr($uri, 0, 1) == "/") $uri = substr($uri, 1); if(strpos($uri, "?")) $uri = substr($uri, 0, strpos($uri, "?")); if ($uri=="") $uri="/"; $path=explode("/",$uri); It just takes a url like site.com/categoryA/categoryB/product-name-id-1234 and breaks it down like: $path[0]=categoryA $path[1]=categoryB $path[2]=product-name-id-1234 OR, sometimes: site.com/categoryA/product-name-id-5678 which is broken down as: $path[0]=categoryA $path[1]=product-name-id-5678 The php script then checks $path[1] for a pattern like this: 'id-1234' If it finds it, it runs the query for displaying product details. If the pattern doesn't match, it simply lists all the products in categoryA. The problem that I am encountering now is that when it is given this URL: site.com/categoryA/product-name-id-5678 It is showing the product details page, which is fine, but it is also running Product list query several times, raising CPU usage to 100%. I think it is quite obvious, looking at the ReWriteLog that it is due to internal redirects to index.php And if I am right, I need to know how to stop internal redirection. Thanks Link to comment https://forums.phpfreaks.com/topic/189718-htaccess-internal-redirects-problem-cpu-load/#findComment-1001597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.