How to use GET parameter to make seo friendly urls

0 votes

I am using a PHP CMS that I've made myself. It fetches the $_GET parameter url and turns it into www.website.com/{url}. This CMS uses the $_GET parameter to get the file. So, if the url is index, then the CMS searches for the file index and returns the contents of the file. But now, I'm expanding the CMS to have an addition parameter like profile/{username}. How can I expand on it? I want my URL to say www.website.com/profile/{username}. How would I go about doing this? This is my current htaccess:

RewriteEngine On  
RewriteRule ^(|/)$ index.php?url=$1  
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1a

Here is the TPL system.

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.'));
    }
}

Is there any other information I need to provide? I need to get this done ASAP, so any advice would be greatly appreciated.

Feb 26 in Others by Kichu
• 19,040 points
147 views

1 answer to this question.

0 votes

What you can do is the following

RewriteEngine On  
RewriteRule ^ index.php

Then in index.php you can have this

$url = str_replace('index.php','', $_SERVER['PHP_SELF']);
$url = str_replace($url,'',$_SERVER['REQUEST_URI']);
$url = explode('/',$url);
$page = array_shift($url);
foreach ($url as $val){
    $args[] = urldecode($val);
}

Now if you open the link www.website.com/profile/someuser/about you will have

$page = 'profile'
$args[0] = 'someuser'
$args[1] = 'about'
answered Feb 27 by narikkadan
• 10,840 points

Related Questions In Others

0 votes
1 answer

How does Stack Overflow generate its SEO-friendly URLs?

/// <summary> /// Produces optional, URL-friendly version of ...READ MORE

answered Feb 28 in Others by narikkadan
• 10,840 points
123 views
0 votes
1 answer

How to use 2000 credit

Your query is very much similar to ...READ MORE

answered May 16, 2020 in Others by Sirajul
• 59,170 points
854 views
0 votes
1 answer

How to use hexadecimal color strings in Flutter?

Hi@akhtar, In Flutter the Color class only accepts integers as parameters, or there ...READ MORE

answered Jul 24, 2020 in Others by MD
• 95,360 points
270 views
0 votes
1 answer

How to use BoxDecoration to a Container widget to draw an image?

Hi@akhtar, The BoxDecoration class provides a variety of ways ...READ MORE

answered Aug 9, 2020 in Others by MD
• 95,360 points
4,798 views
0 votes
1 answer

Generate SEO friendly URLs (slugs)

function format_uri( $string, $separator = '-' ) {     $accents_regex ...READ MORE

answered Feb 14 in Others by narikkadan
• 10,840 points
57 views
0 votes
0 answers

SEO friendly url using php

I wanted to use php to make ...READ MORE

Feb 18 in Others by Kichu
• 19,040 points
36 views
0 votes
1 answer

Creating SEO friendly urls using htaccess

its just a simple step just use ...READ MORE

answered Feb 20 in Others by narikkadan
• 10,840 points
31 views
0 votes
1 answer

Generate SEO friendly URLs- Slugs

// source: https://code.google.com/archive/p/php-slugs/ function my_str_split($string) { ...READ MORE

answered Feb 22 in Others by narikkadan
• 10,840 points
58 views
0 votes
1 answer

How can I create custom SEO-friendly URLs in OpenCart?

Index: catalog/controller/common/seo_url.php =================================================================== --- catalog/controller/common/seo_url.php (old) +++ catalog/controller/common/seo_url.php ...READ MORE

answered Feb 21 in Others by narikkadan
• 10,840 points
33 views
0 votes
1 answer

How to use next-seo for setting nextjs meta tag with multiple OGP images?

https://github.com/garmeeh/next-seo use this git repo that contains ...READ MORE

answered Feb 24 in Others by narikkadan
• 10,840 points
259 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP