【问题标题】:htaccess - redirect DNS entry to sub folder but without sub folder in urlhtaccess - 将 DNS 条目重定向到子文件夹,但 url 中没有子文件夹
【发布时间】:2014-06-03 13:10:15
【问题描述】:

我的问题是我的域 example.com 指向我服务器的根目录(正常行为),但网站位于子目录 sub 中。 p>

通过以下 .htaccess 我实现了我的域被重定向到子目录 sub 而无需更改 URL!

RewriteEngine On
RewriteRule !^/sub /sub%{REQUEST_URI} [L,NC]

首页显示正确,网址仍然是example.com(没错)。但是当我点击一个链接访问子页面(示例链接:example.com/my-company)时,该页面将我重定向到 example.com/sub(所以回到首页 - 我不想那样)。重定向后这些链接仍然不起作用。

如何在没有地址栏中的子文件夹的情况下实现这些链接的工作?总结一下:

我将我的域 example.com 重定向到名为 sub 的子文件夹,并且不在地址栏中显示文件夹 sub。我希望整个页面在地址栏中没有 sub 文件夹的情况下工作。

在后台我们使用typo3。这是 sub 文件夹的 .htaccess

Options None
Options +FollowSymlinks

RewriteEngine On
RewriteBase /sub

RewriteRule ^(typo3|t3lib|tslib|fileadmin|typo3conf|typo3temp|uploads|showpic\.php|favicon\.ico)/ - [L]
RewriteRule ^typo3$ - [L]
RewriteRule ^typo3/.*$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php

# to avoid double content
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

那么,我该如何实现呢?

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    这是因为 RewriteRule 默认会发出重定向。您需要告诉它不要执行重定向。您可以使用 PassThrough 浮动 [PT]

    来执行此操作

    以下应该可以工作:

    RewriteRule !^/sub/(.*)$ /sub/$1 [L,NC,PT]
    

    【讨论】:

    • 谢谢。现在,它会重定向到没有子文件夹的页面,但不会显示该站点。它保持空白。
    • 我编辑了我的答案。如果您直接查询 /sub 下的页面会发生什么?
    • 我编辑了我的 htaccess:首页现在加载了错误的 css/js 文件,因为 base-href 指向的是 example.com 而不是 example.com/sub。我在typo3中更改了baseURL,但这没有帮助。
    • 当我查询网址 example.com/sub/my-company 时,它可以工作。但是当我查询 example.com/my-company 时仍然没有
    • 更新:当我查询 example.com/my-company 时,网站会将我重定向回 example.com/sub
    猜你喜欢
    • 2013-09-23
    • 2016-12-17
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 2015-04-09
    • 2016-06-27
    相关资源
    最近更新 更多