0

我的网站位于根网站 .com/ 我想设置一个像这个网站 .com/us/ 这样的文件夹

文件夹 /us/ 是空的,当有人访问该文件夹时,该文件夹显示的内容与网站 .com 中的内容相同,但仍保留在网站 .com/us/ 上。

这是一个转折点,如果我想显示不同的 header.php 或 js 或 css 文件并将其加载到域网站 .com/us/ 中,我需要使用 htaccess 来使用它而不是网站 .com/ 上的内容。我将使用相同的目录结构。

4

1 回答 1

0

这是您可以解决的许多方法之一。这是一个使用 mod_rewrite 和 php5 的粗略示例,希望能让您朝着想要的方向前进。

使用下面的示例导航到应该如下所示

.htaccess

<IfModule php5_module>
    php_value auto_prepend_file /var/www/vhosts/example.com/httpdocs/header.php
    php_value auto_append_file  /var/www/vhosts/example.com/httpdocs/footer.php
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^us/?$    /index\.php?tpl=us    [QSA,L]

    RewriteCond %{DOCUMENT_ROOT}/$1 !-f
    RewriteRule ^us/(.*)$    /$1?tpl=us    [QSA,L]
</IfModule>

/header.php

<?php 
$tpl = $_GET['tpl'];
if ($tpl === 'us') {
    require_once $_SERVER['DOCUMENT_ROOT'].'/header-us.php';
}
else {
    require_once $_SERVER['DOCUMENT_ROOT'].'/header-default.php';
}
?>

/header-us.php

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
  <title>USA</title>
  <meta name="description" content="Welcome to the US section">
  <link rel="stylesheet" href="/css/us/style.css">
  <script src="/js/us/scripts.js"></script>
</head>
<body>

/header-default.php

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
  <title>Welcome to index</title>
  <meta name="description" content="Welcome to the DEFAULT section">
  <link rel="stylesheet" href="/css/style.css">
  <script src="/js/scripts.js"></script>
</head>
<body>

/页脚.php

<p>user contributions licensed under cc-wiki with attribution required</p>
</body>
</html>

/index.php

Content

/some-other-directory/file.php

Different Content in some other directory
于 2012-10-24T14:00:21.470 回答