如何在网址末尾添加斜杠?

时间:2014-07-31 17:42:18

标签: php html .htaccess

我想知道如何在所有网址的末尾添加斜杠?我已经使用.htaccess来删除.php扩展名:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

现在,我想在所有网址的末尾添加斜杠。这是我的index.php文件:

<!DOCTYPE html>
<html lang="en-us">
    <head>
        <meta charset="UTF-8">
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "index") !== false) { ?>
        <title>Test - Forums</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "members") !== false) { ?>
        <title>Test - Members</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "sign_up") !== false) { ?>
        <title>Test - Sign Up</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "sign_in") !== false) { ?>
        <title>Test - Sign In</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "change_theme") !== false) { ?>
        <title>Test - Change Theme</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "contact_us") !== false) { ?>
        <title>Test - Contact Us</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "help") !== false) { ?>
        <title>Test - Help</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "rules") !== false) { ?>
        <title>Test - Rules</title>
        <?php } ?>
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <?php include("top_bar.php");?>
        <?php include("header.php");?>
        <?php include("container.php");?>
        <?php include("footer.php");?>
    </body>
</html>

和我的top_bar.php:

<!-- TOP BAR -->
<div id="top_bar">
    <div class="wrapper">
        <div id="top_bar_links">
            <ul>
            <?php
            $full_name = $_SERVER["PHP_SELF"];
            $name_array = explode("/",$full_name);
            $count = count($name_array);
            $page_name = $name_array[$count-1];
            ?>
            <li>
                <a id="home" href="../">Home</a>
            </li>
            <li>
                <a id="forums" class="<?php echo ($page_name=="index.php")?"active":"";?>" href=".">Forums</a>
            </li>
            <li>
                <a id="members" class="<?php echo ($page_name=="members.php")?"active":"";?>" href="members">Members</a>
            </li>
            </ul>
        </div>
    </div>
</div>

我的所有文件都放在名为&#34; community&#34;:http://prntscr.com/487rhj

的文件夹中

我该怎么办?

感谢。

1 个答案:

答案 0 :(得分:-1)

href="<?php echo $page_name. "/"; ?>"

OR

href="<?php echo "{$page_name}/"; ?>"

如果我理解你的问题,那么其中任何一个都应该可以正常工作