URL重写(弹头)和URL重定向(htaccess的)重写、弹头、重定向、URL

2023-09-02 00:50:19 作者:顽皮可以别赛脸

下面是我的PHP code(qs.php)。此文件包含的URL链接。创建使用弹头pretty的链接。

Below is my php code(qs.php). This file contain url links. Pretty links created by 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>

上面的链接出现这样的 - 的http://本地主机/ QS / QS1 / 12345678 /塞文测试目的只

修改

QS是所有文件都放在一个目录。 QS1是一个PHP文件(qs1.php)

QS is a directory where all files are placed. QS1 is a php file (qs1.php)

我想从上面的链接 12345678放大器得到两个变量;塞文测试目的只。 作为qs1.php的文件,其中我从 $ _ GET ['VAR1']放这两个变量; $ _GET [VAR2'];

I want to get two variable from above link 12345678 & slug-text-testing-purpose-only. as qs1.php is file where i get these two variables from $_GET['var1'] & $_GET['var2'];

我知道它可以通过的.htaccess 来实现。我尝试多种选择,但他们没有工作,因为我得到404。

I know it can be achieved by .htaccess. i tried multiple options but they are not working as i am getting 404.

.htaccess文件放置在QS目录。

.htaccess file is placed on QS directory.

下面是我曾经尝试过的选项。

Below are the options i had 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]

我很新的htaccess以及URL重定向。

I am very new to htaccess and url redirect.

请指教。

感谢

推荐答案

您可以把这个code。在 /qs/.htaccess

You can put this code in /qs/.htaccess

RewriteEngine On
RewriteBase /qs/

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

现在,你可以去的http://本地主机/ QS / QS1 / 12345678 /塞文测试目的只,你会得到同样的内容 /qs/qs1.php?var1=12345678&var2=slug-text-testing-purpose-only

Now, you can go to http://localhost/qs/qs1/12345678/slug-text-testing-purpose-only and you'll get the same content as /qs/qs1.php?var1=12345678&var2=slug-text-testing-purpose-only

 
精彩推荐