[HTACCESS] Multiple URL Segments

IntactDev

Member
Nov 22, 2012
399
71
I'm trying to add a new feature to my TPL system. I want to be able to add the ability to have multiple URL segments, like (profile/Username/Photos). Right now, I can only do one segment (profile/). How can I add more? I'm learning HTACCESS and I took a shot. My TPL system uses the first segment to identify which page to return... but, I now want it to check if the first segment is profile. Here is the pseudo verson:

PHP:
if(First Segment is == profile) {
check the second segment, and return that page template
} else {
continue code
}

Here is my current HTML:
Code:
RewriteEngine On
 
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1
 
RewriteRule ^profile/([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1&username=$2

Here is the current PHP:
PHP:
public function addTpl() {   
        global $zip;
       
        if(!isset($_GET['url']) || empty($_GET['url'])) {
            $_GET['url'] = 'index';
        }
       
        if(file_exists('_zip/_templates/_front/'. $zip['Template']['Front'] . '/')) {
            if(file_exists('_zip/_templates/_front/'. $zip['Template']['Front'] . '/' . secure($_GET['url']) . '.php')) {
                ob_start();
                include('_zip/_templates/_front/'. $zip['Template']['Front'] . '/' . secure($_GET['url']) . '.php');
                $this->tpl .= ob_get_contents();
                ob_end_clean();
            } else {
                die(zipError('File Not Found', 'The file <b>' . secure($_GET['url']) . '</b> could not be found. Please re-check the URL; If you were directed here using a link, please report that link.'));
            }
        } else {
            die(zipError('Template Not Found', 'The template <b>' . $zip['Template']['Front'] . '</b> could not be found. Please check your configuration file for a mistake.'));
        }
    }

How can I go about doing this? I hope this is enough info,

IntactDev
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Right now I have something like this in my htaccess

Code:
RewriteEngine On
RewriteRule ^index$ index.php [L]
 
 
RewriteEngine On
RewriteBase /
RewriteRule ^index/page/([a-z-0-9]+)/?$ index.php?page=$1 [NC,QSA,L]

It allows you to put localhost/index/page/[num] instead of index.php?page=[num]
Maybe you could get something from this?
 

IntactDev

Member
Nov 22, 2012
399
71
Right now I have something like this in my htaccess

Code:
RewriteEngine On
RewriteRule ^index$ index.php [L]
 
 
RewriteEngine On
RewriteBase /
RewriteRule ^index/page/([a-z-0-9]+)/?$ index.php?page=$1 [NC,QSA,L]

It allows you to put localhost/index/page/[num] instead of index.php?page=[num]
Maybe you could get something from this?

What does that [NC,QSA,L] mean?
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
"To combine new and old query strings, use the [QSA] flag"
Source:

"The "NC" flag indicates the condition is case-insensitive"
Source:

"The [L] flagterminates rewriterule processing only if the current rule is invoked"
Source:
 

Users who are viewing this thread

Top