lol25500
lol25500

Reputation: 92

$_GET & .htaccess | PHP ignorer values

I got this problem, where I try to make an Image Archive. Most of it works, but I have now come to prettifying URLs. I have worked with this before, but somehow, it don't work now. If I add more then one Rewrite URL to the same file (index), it ignores the values added with it.

What I got:

Header add "disablevcache" "true"

RewriteEngine On
RewriteBase /folder/
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteRule ^archive/([^/]+)?$                              archive/index.php?cat=$1 [E=ORIG_URI:/$1]
RewriteRule ^archive/([^/]+)/([^/]+)?$                      archive/index.php?cat=$1&sub=$2 [E=ORIG_URI:/$1]
RewriteRule ^archive/([^/]+)/([^/]+)/([^/]+)?$              archive/index.php?cat=$1&sub=$2&id=$3 [E=ORIG_URI:/$1]
RewriteRule ^archive/([^/]+)/([^/]+)/([^/]+)?/([^/]+)$      archive/index.php?cat=$1&sub=$2&id=$3 [E=ORIG_URI:/$1]

The following should allow me to access these URLs:

domain.com/archive/category
domain.com/archive/category/subcategory/
domain.com/archive/category/subcategory/id
domain.com/archive/category/subcategory/id/item

domain.com/archive will be made default, since I use an index.php file, in a folder. And item will just be for SEO and has nothing to do with PHP. (The last rewriteRule)

This works. I can access the same page, from all the different URLs. (archive/index.php). But when I try to use PHP to get the value from the provided URLs, it won't work. I can't even check and see if there are values.

No matter what I do, it just echo out Category & Sub Category on every URL. Also if I go to the default URL, domain.com/archive.

if($_GET['cat']){

    echo 'Category';

    if($_GET['sub']){

        echo 'Sub Category';
    }
}

Anyone who can see what I am doing wrong or got a suggestion to why it ignore my values? Or maybe know another way to do this, so I end up with the same result?

Upvotes: 0

Views: 67

Answers (1)

Anonymous
Anonymous

Reputation: 12017

Apache rewrites in a loop. You need to stop it for archive/index.php since that always matches the first RewriteRule:

RewriteRule ^archive/index\.php$                            - [L]
RewriteRule ^archive/([^/]+)?$                              archive/index.php?cat=$1 [E=ORIG_URI:/$1]
RewriteRule ^archive/([^/]+)/([^/]+)?$                      archive/index.php?cat=$1&sub=$2 [E=ORIG_URI:/$1]
RewriteRule ^archive/([^/]+)/([^/]+)/([^/]+)?$              archive/index.php?cat=$1&sub=$2&id=$3 [E=ORIG_URI:/$1]
RewriteRule ^archive/([^/]+)/([^/]+)/([^/]+)?/([^/]+)$      archive/index.php?cat=$1&sub=$2&id=$3 [E=ORIG_URI:/$1]

You can also remove [E=ORIG_URI:/$1] if you don't use it.

Upvotes: 2

Related Questions