【问题标题】:htaccess Redirect to Sub Directorieshtaccess 重定向到子目录
【发布时间】:2019-02-19 07:20:36
【问题描述】:

所以我在 var/www/html 中有不同的文件夹用于不同的项目 我想将 www.testing.com 重定向到 var/www/html/test,所以我添加了一个 .htaccess 文件并添加了以下内容在文件中:

RewriteEngine On
RewriteCond %{HTTP_HOST} testing\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /test/$1 [L]

它运行良好,现在当我转到 www.testing.com 时,我重定向到 /test 索引文件,只是没有检索到网站中的资产.

例如,带有 www.testing.com/images/k.png url 的图像返回 404。 我不想更改图像或任何内容的 url,我需要使用 htaccess 配置将它们重定向到 /test。

【问题讨论】:

    标签: .htaccess redirect apache2


    【解决方案1】:

    因为你在第 3 行写了^/$,它说你所有的网址都以/ 结尾,但www.testing.com/images/k.png 不以/ 结尾,所以你可以把它改成^/(.*)$ 它说你可以在/ 之后有一些东西最后你的代码改为:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} testing\.com [NC]
    RewriteCond %{REQUEST_URI} ^/(.*)$
    RewriteCond %{REQUEST_URI} !^/test/ [NC]
    RewriteRule ^(.*)$ /test/$1 [L]
    

    【讨论】:

    • 它给了我一个内部服务器错误 500。从 apache 日志它显示 Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
    • 通过添加一行可以在您的服务器中更正它,我编辑我的帖子,这个新条件排除了在开始时有测试的网址
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多