How do I set base URL for all pages of my website?

后端 未结 3 1654
梦谈多话
梦谈多话 2020-12-06 12:14

How do I set a base URL for my website and get it to include in every page?

Is there a way for me to easily change a variable to be the base url for the website, suc

相关标签:
3条回答
  • 2020-12-06 12:23

    (xampp), the How do I use on the local computer. folder layout,

    http://www.resimagaci.com/img/90rvnrf.png

    ust.php

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    </head>
    <body>
    

    alt.php

    </body>
    </html>
    

    sabitler.php

    <?php
    #sabitler
    define('BASE_URL', 'base-url');
    ?>
    

    index.php

    <?php
    include 'kutuphane/sabitler.php';
    ?>
    <?php
    $ust= BASE_URL . '/kutuphane/ust.php';
    $alt= BASE_URL . '/kutuphane/alt.php';
    ?>
    <?php
    include ($ust);
    ?>
    <?php
    include ($alt);
    ?>
    
    0 讨论(0)
  • 2020-12-06 12:24

    You can’t make both PHP and client-side assets use the same base URL, unless you use PHP to echo a base URL variable or constant to the page.

    The usual approach is to have a bootstrap file that you include on every page, and define your base URL and other site-wide variables in there.

    bootstrap.php:

    <?php
        define('BASE_URL', 'http://example.com');
    

    index.php:

    <?php
        include('bootstrap.php');
    ?>
    <!DOCTYPE html>
    <html>
      <head>
        <!-- // -->
        <link rel="stylesheet" href="<?php echo BASE_URL; ?>/css/styles.css" />
      </head>
      <body>
        <!-- // -->
      </body>
    </html>
    
    0 讨论(0)
  • 2020-12-06 12:37

    You may want to take a look at the html base tag.

    Inside the <head> section of your html, put

    <base href="http://www.website.com/website/">
    

    On top of that, you may want to have a base.php with default directories and whatnot that you include into your project.

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