Rewrite URL with .htaccess

后端 未结 2 1984
醉梦人生
醉梦人生 2021-01-23 09:59

I\'ve this url: http://www.test.com/page.php?k=m1ns

and I want this one: http://www.test.com/r/m1ns

My .htaccess:

Options +FollowSymlinks
Rewrite         


        
相关标签:
2条回答
  • 2021-01-23 10:37

    Try this

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^r/(.*)/ /page.php?k=$1 [L]
    

    It should work regardless of whether or not www is entered.

    0 讨论(0)
  • 2021-01-23 10:38
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^r/([^/]*)$ /page.php?k=$1 [L]
    

    On your top page.php

    if (strstr($_SERVER['REQUEST_URI'], '/page.php?k=' . $var . '')) {
        header("HTTP/1.1 301 Moved Permanently");
        header("location:http://www.test.com/r/" . $var );
        exit();
    }
    
    0 讨论(0)
提交回复
热议问题