【问题标题】:Is it possible to use one file for two or more directories with htaccess?是否可以通过 htaccess 将一个文件用于两个或多个目录?
【发布时间】:2016-11-18 23:17:28
【问题描述】:

我的主目录中有一个 index.php 文件,并且希望其他子目录也使用该文件。因此,当用户调用 example.com/subdirectory-1/example.com/subdirectory-2/ 时,他应该会看到 index.php 我的主目录的文件。

这可以通过 htaccess 文件实现吗?

【问题讨论】:

    标签: apache .htaccess url


    【解决方案1】:

    在文档根目录的 htaccess 中,添加以下内容:

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ /index.php [L]
    

    这会将所有现有的子目录重写为 /index.php 。

    【讨论】:

    • 感谢您的回答。不幸的是,我没有正确表达自己。我不想将所有子目录重定向到 index.php 文件,而只是其中一些。我需要这个用于多语言网站,所以 example.com/en/example.com/fr/ 应该使用相同的文件,但 example.com/images / 不是。可以安排这个吗?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-12
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多