【问题标题】:Redirect all traffic to one sub-directory with httpd.conf使用 httpd.conf 将所有流量重定向到一个子目录
【发布时间】:2013-04-18 23:21:48
【问题描述】:

我有一个httpd.conf 文件,在我的服务器上配置了许多域。我需要将一个网站上的旧目录重定向到新目录。

基本上,当用户访问目录 domain.com.au/store 中的任何页面时,我希望他们被重定向到 domain.com.au/shop

我不希望重定向包含旧网络路径,因此任何旧 URL 只需重定向到 domain.com.au/shop 页面,而不是 /shop/old_webpath

我尝试了许多来自网络的重定向条目,但似乎都无法正常工作,因为它们都重定向到/shop/old_webpath,而不仅仅是/shop

任何 apache 头脑都可以帮忙吗?

【问题讨论】:

    标签: apache redirect httpd.conf


    【解决方案1】:

    .htaccess 文件中试试这个:

    Options +FollowSymLinks -MultiViews
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^store/(.*)$ \/shop
    </IfModule>
    

    更新domain.com.au 的 apache 配置中的虚拟主机:

    <VirtualHost *:80>
        # ...
        <Directory "[your_path]">
            # ...
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{HTTP_HOST} ^domain\.com\.au$ [NC]
            RewriteRule ^store/(.*)$ \/shop
        </Directory>
    </VirtualHost>
    

    【讨论】:

    • 谢谢,但有没有办法将它添加到 httpd.conf 并将其限制为特定的 URL?否则任何网站上的 /store 都会重定向到任何网站上的 /shop
    • 非常感谢,但即使我启用了重写模块,包括RewriteBase / 也会导致 Apache 重新启动失败并且条目无效。
    • 删除带有RewriteBase的行并重新启动Apache,如果规则在vhost配置中,则必须仅适用于此vhost
    • 仍然没有运气,我的虚拟主机配置如下:&lt;VirtualHost *:80&gt; ServerAlias domain1.com domain2.com domain3.com.au domain4.com.au domain5.com ServerName domain.com
    • 有这么简单的事情吗?:Redirect permanent http://domain.com.au/store http://domain.com.au/shop
    猜你喜欢
    • 2011-10-16
    • 2017-02-20
    • 1970-01-01
    • 2014-10-16
    • 2019-11-02
    • 1970-01-01
    • 2014-04-09
    • 2023-03-27
    • 2018-05-23
    相关资源
    最近更新 更多