Forum Moderators: coopster

Message Too Old, No Replies

$_GET navigation and Search Engine Friendly URL

Having strange issue

         

xKillswitchx

6:22 pm on Feb 19, 2008 (gmt 0)

10+ Year Member



Hello all,
I am having a strange issue with my GET navigation and SEF URLs. Basically, I use GET to check the category and again for the sub content. If no content is set, I call the cateogry template, else I call the content template.

The category displays fine, site.com/category.

But when I try site.com/category/content it doesnt see $_GET['content'] as being set. Ive tried checking by simply echoeing 'Is set' if GET['content'] is set, but nothing.

Any help would be much appreciated.

PHP_Chimp

7:11 pm on Feb 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The GET will be anything after the ?, so as you have no ? there is no GET...unless of course you mean that the -
site.com/category/content
is actually something like -
site.com/?category=0&content=0
After mod_rewrite has done its work.

You said about SEF URL's so I dont know if the url you gave was after or before the rewrite.

So what do your url's look like before the rewrite?
<edit>
Also what rewrite rules are you using? As it could be a problem with those rather than the php.

[edited by: PHP_Chimp at 7:12 pm (utc) on Feb. 19, 2008]

xKillswitchx

1:27 am on Feb 20, 2008 (gmt 0)

10+ Year Member



Yes, my URL without mod_rewrite is category=some_category&content=some_content

With mod_rewrite, it only works on category, content isnt seen as being set.

I've seen some people say that you cant use GET with this, but really dont know how else to go about this.

I am thinking possibly about trying to get the contents of the URL in an array, since category GET is seen, then just go through some switches. Would this be possible or right to do in this situation? Ive never designed a dynamic frontend before with a CMS and am a little lost on techniques to go about this.

whoisgregg

1:55 pm on Feb 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like the problem could be with your mod_rewrite rules. If you'd like to post those we can take a look. :)

PHP_Chimp

10:19 pm on Feb 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I agree that your problem is more likely with mod_rewrite.

As if you are going from -
site.com/?category=something&content=another_thing
to -
site.com/category/content
Then it looks as though you are loosing a lot of that information.

For example, this would be a more usual type set up
site.com/?category=something&content=another_thing
to -
site.com/something/another_thing

As in your are keeping the keys, but loosing the values. So in my case you know that the first 'directory' is actually your category and the page name is the content.

So there may well be only a very small change needed to your rewrite rules to get the values preserved...or of course I could have the wrong end of the stick ;)

xKillswitchx

11:11 pm on Feb 20, 2008 (gmt 0)

10+ Year Member



My rewrite rules :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+) index.php?category=$1&content=$2 [L]

I am going from category=category&content=content, but content is never seen as being set. Could it be that I use isset to check the category, and if category is set I use another isset to check if content is set? This way, content is only pulled if the category is set.

I have found another method that seems to work at the moment. I simply set an array for te URL and exploded starting at the category /, getting everything afterwards. This way, foreach value in the URL, I could use something like $url[0] and $url[1]. It works so far, but still would like to know why the GET method wasnt working two levels deep.

whoisgregg

2:08 pm on Feb 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The requests for the content subdirectory pages are being handled by the first rule which matches:

RewriteRule ^(.*)$ index.php?category=$1 [L]

Just move your more specific rule above that one and it should work:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+) index.php?category=$1&content=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]