URL rewrite (SLUG) and URL redirection (htaccess)

Below is my PHP code (qs.php). This file contains URL links. Pretty links created using SLUG.

<html>
<head></head>
<body>
    <?php
    function create_slug($string){
       $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
       $slug = strtolower($slug);
       return $slug;
    }
    $slugurl=  create_slug('SLUG-text-testing-purpose-only');

    $file = 'qs1'; //this is a php file qs1.php
    $id = '12345678'; //testing ID
    $complete_url = $file."/".$id."/".$slugurl;

    ?>
    <a href ="<?php echo $full;?>"> This is a test link created by slug</a>

</body></html>

The above links look like this: http://localhost/qs/qs1/12345678/slug-text-testing-purpose-only

Edit

QS is the directory in which all files are placed. QS1 is a php file (qs1.php)

I want to get two variables from the above link 12345678 & slug-text-testing-purpose-only. since qs1.php is the file in which I get these two variables from$_GET['var1'] & $_GET['var2'];

I know that this can be achieved .htaccess. I tried several options, but they do not work, since I get 404.

The .htaccess file is placed in the QS directory.

Below are the options I tried.

RewriteEngine On
    RewriteRule ^qs/([0-9]+)/([^/]+)$ qs1.php?var1=$1&var2=$2 [L]

    RewriteRule ^/([^/]*)/([^/]*)$ /qs1.php?var1=$1&var2=$2 [L]

    RewriteRule  ^qs/([^/]+)/([^/]+)/?$ /qs1.php?var1=$1&var2=$2  [QSA,L]
    RewriteRule /qs/(\d+)/(.*) qs1.php?id=$1&slug=$2    [QSA,L]

I am very new to htaccess and URL redirection.

Please inform.

thank

+3
2

/qs/.htaccess

RewriteEngine On
RewriteBase /qs/

RewriteRule ^([^/]+)/(\d+)/([^/]+)$ $1.php?var1=$2&var2=$3 [NC,L]

http://localhost/qs/qs1/12345678/slug-text-testing-purpose-only, , /qs/qs1.php?var1=12345678&var2=slug-text-testing-purpose-only

+2
RewriteEngine On
RewriteRule    ^qs/qs1/(\d+)/(.+)$    qs1.php?var1=$1&var2=$2    [NC,L]

: http://htaccess.madewithlove.be

0

All Articles