Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 需要使用htaccess帮助的测试站点_.htaccess - Fatal编程技术网

.htaccess 需要使用htaccess帮助的测试站点

.htaccess 需要使用htaccess帮助的测试站点,.htaccess,.htaccess,我的网站位于root website.com/我想设置一个类似于此website.com/us的文件夹/ 文件夹/us/是空的,当有人转到该文件夹时,该文件夹显示的内容与website.com中的内容相同,但仍保留在website.com/us/上 这里是一个转折点,如果我想显示不同的header.php或js或css文件,并将其加载到域网站.com/us/,我需要htaccess来使用它,而不是website.com/。我将使用相同的目录结构。以下是许多方法之一。这是一个使用mod_rewri

我的网站位于root website.com/我想设置一个类似于此website.com/us的文件夹/

文件夹/us/是空的,当有人转到该文件夹时,该文件夹显示的内容与website.com中的内容相同,但仍保留在website.com/us/上


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

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

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

  • 应使用header-default.php标题显示“内容”
  • 应使用header-us.php标题显示“内容”
  • 应使用header-default.php标题显示“其他目录中的不同内容”
  • 应使用header-us.php标题显示“其他目录中的不同内容”
.htaccess /其他一些目录/file.php
你正在尝试建立一个多语言网站吗?那么i18n就是术语!是的,我们将访问区域网站,然后使用rel=“alternate”hreflang=“x”帮助谷歌提供正确的语言或区域URL。htaccess没有办法说嗨,如果/us/中没有文件,则转到root,如果/us/中有文件,则使用此命令并从root获取其余文件?我知道有些开发人员有测试站点,其中有一个url,比如/test/,如果他们想将一个文件转换为测试文件,则只将该文件加载到测试文件夹中,其余文件将从主站点中提取。@William yes,使用正确的
RewriteCond
我为您做了一个,但我会用PHP做您所指的事情。使用一个catch all,然后进行文件/目录检查和包含。感谢我在本地计算机上测试的代码。它将一个查询附加到我们希望避免的url上。“有什么办法可以把它去掉吗?”威廉对我来说很好,你肯定还有别的办法。比如301重定向或其他代码。
<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>
<?php 
$tpl = $_GET['tpl'];
if ($tpl === 'us') {
    require_once $_SERVER['DOCUMENT_ROOT'].'/header-us.php';
}
else {
    require_once $_SERVER['DOCUMENT_ROOT'].'/header-default.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>
<!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>
<p>user contributions licensed under cc-wiki with attribution required</p>
</body>
</html>
Content
Different Content in some other directory