Forum Moderators: phranque
Below is the htaccess file I'm using:
php_value session.use_only_cookies 1
php_value session.use_trans_sid 0RewriteEngine on
Options FollowSymLinks Includes
RewriteCond %{QUERY_STRING} ^main_page=index&cPath=(.*)$
RewriteCond %{QUERY_STRING}!^action=(.*)$
RewriteRule ^index.php(.*)$ seourl.php?convert=cat&id=%1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ seourl.php?category=$6 [L,QSA]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ seourl.php?category=$5 [L,QSA]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ seourl.php?category=$4 [L,QSA]
RewriteRule ^(.*)/(.*)/(.*)/$ seourl.php?category=$3 [L,QSA]
RewriteRule ^(.*)/(.*)/$ seourl.php?category=$2 [L,QSA]
RewriteRule ^(.*)/$ seourl.php?category=$1 [L,QSA]
And I've tried a few variations, but no luck. I saw the post in 2005 located here:
But that was left fairly open-ended and I wasn't able to find anything online that would help me in over an hour.
Be aware that RewriteConds apply only to the first single rule that follows them. Your code will need some restructuring if your "-f -d" checks are to be applied to all of your last set of rules.
Your URL-path patterns are highly-inefficient, and may slow your server noticeably. As an example, your most complex pattern will execute much more efficiently if rewritten as:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$6 [L,QSA]
Jim
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$6 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$5 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$4 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/$ seourl.php?category=$2 [L,QSA]
RewriteRule ^([^/]+)/$ seourl.php?category=$1 [L,QSA]
UPDATE: I'm now looking at your previous post at [webmasterworld.com ]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [S=6]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$6 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$5 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$4 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ seourl.php?category=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/$ seourl.php?category=$2 [L,QSA]
RewriteRule ^([^/]+)/$ seourl.php?category=$1 [L,QSA]
First, examine the script to determine how it "GETs" the requested URL-path info to figure out what page content to serve. It may use a GET() function, or it may directly examine server variables. If the latter, make sure that each variable that it examines is one that is updated by mod_rewrite; Otherwise it may be looking at the SEO-friendly URL and getting lost.
The other thing you might try is to install the "Live HTTP Headers" add-on for Firefox and Mozilla browsers, clear your cache(s), and surf into your site to see if/when the query string and/or cookie is getting dropped or modified. Beyond that, adding a few "echo" statements to output query/cookie status at the bottom of each page might also give you some troubleshooting direction.
Jim
HTTP/1.x 200 OK
Content-Type: text/html
Server: Microsoft-IIS/6.0
X-Powered-By: PHP/5.1.4, ASP.NET
Date: Mon, 03 Dec 2007 16:42:12 GMT
Connection: close
where as pages that aren't rewritten, this is returned
HTTP/1.x 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/html; charset=iso-8859-1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: PHP/5.1.4, ASP.NET
Set-Cookie: cookie_test=please_accept_for_session; expires=Wed, 02-Jan-2008 16:43:56 GMT; path=/; domain=mysub.mydomain.com
Date: Mon, 03 Dec 2007 16:43:57 GMT
Connection: close
I'm not sure why it's not doing the right thing on the rewritten URLs. Thanks for your help, you have helped me a great deal already.
Jim
session_start()function call in PHP. There are few cases when the cache headers and the cookies are not set:
output_bufferingis not enabled, because then a single character can cause this behavior;
include_once "http://mysub.mysite.com/index.php?main_page=index&cPath=4_6";
UPDATE: Instead of including the PHP page with a remote URL, I included the index.php locally and set the $_GET variables correctly. That did not work. My only solution to get it to work was to copy everything from index.php and put it at the bottom of my seourl.php page. From there, I set the $_GET variables at the top based upon the HTACCESS response and my function to convert from the URL name into the cPath. This works! I just wish I knew a way to get around having all of the php from index.php in there!
I just noticed something about your code that I hadn't noted before. If all you want to do is extract the last path-part to use as "category," then all of your rules above can be replaced by this one:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+)/)*([^/]+)/$ seourl.php?category=$3 [L,QSA]
Running this one rule will be faster than running the seven rules above.
Jim
I've got the URLs using a formated version of the product titles. From there, it goes through the htaccess and goes to a php file that grabs the correct cPath for the page and then this code pulls the correct page.include_once "http://mysub.mysite.com/index.php?main_page=index&cPath=4_6";
That's why your sessions are broken, when you do an
include_oncewith a fully qualified URI, the PHP will open a HTTP connection to that address, and fetch that resource and returns it to the browser. This is done in a separate process, it has no direct relation to the first request, no cookies, no additional headers will make it through (in nether directions). So if you browse to the seo page, your browser will send the appropriate cookies, but when the URI is fetched by
include_once, these cookies are not forwarded, and when the response to the
include_oncecontains headers or cookies, those are also ignored, they are not sent back to the browser. So the reason you loose session state is that you use fully qualified URI with the
include_once.
If I remember well you can pass parameters in the same way to locally included files as you would do with remote resources, so the
include_once "index.php?main_page=index&cPath=4_6";
is also valid, and this will make the $_GET array properly set in the index.php. See [php.net...]
Anyway, it is clear that it is a PHP issue from now on :-)