Get Text after domain name from URL without sending to not found page

后端 未结 2 798
离开以前
离开以前 2021-01-27 07:02

I have a domain name say for example : www.example.com I would like to get a dynamic data using PHP that is after this domain name. Example : www.example.com/samsung

相关标签:
2条回答
  • 2021-01-27 07:38

    This will give you last part of url

    $url = $_SERVER['PHP_SELF'];
    $url_array = explode('/',$url);
    $result = end($url_array);
    $Cleaned_url = str_replace("?", "", $result);
    echo $Cleaned_url;
    

    UPDATE : Creating Seo url :

    .htaccess File

    RewriteRule ^([a-zA-Z0-9_-]+)$ your_page.php?p=$1 [L,NC]
    

    In php file when linking to url.

    I save urls in database in news_url column

    <a href="<?php echo $row["news_url"]; ?>" title="">post title</a>
    

    This setup will give you www.example.com/samsung and solve your 404 notfound problem with right setup. Attetion : Creating seo urls with htaccess requires knowledge just copy paste wont work.

    you can search on google : for how to create seo url with htaccess

    This examples are working 100%.

    0 讨论(0)
  • 2021-01-27 07:56

    Use parse_url. See also this answer

    0 讨论(0)
提交回复
热议问题