Apache的重定向所有子页面的主页,除了特定页面 [英] Apache redirect all sub pages to home page except specific pages

查看:168
本文介绍了Apache的重定向所有子页面的主页,除了特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站的结构像这样的:

I have a site structure such as this:

www.domain.com
www.domain.com/subpage-a
www.domain.com/subpage-b
www.domain.com/terms
www.domain.com/request-information

我想配置Apache的重写规则,这将指向全部子页面的主页,禁止特定的页面。

I am trying to configure an Apache rewrite rule which will point all sub pages to the home page, bar specific pages.

使用上面的例子中,我需要到现场的所有子页面重定向到首页,巴说条款请求 - 信息页。

Using the example above I would need to redirect all the sub pages of the site to the home page, bar say the terms and request-information pages.

我一直在寻找的计算器和我发现无人接听了几个问题,如<一个href=\"http://stackoverflow.com/questions/6326062/redirect-all-pages-except-one-page-to-sub-domain-htaccess\">this 之一和这个。第二个链接似乎有种做我想做的,但我不知道如何重写我的规则特定页面。

I have been looking on StackOverflow and I've found a few questions that went unanswered, such as this one and this one. The second link seems to kind of do what I want but I'm not sure how to override my rule for specific pages.

目前,我的Apache文件看起来是这样的:

Currently, my Apache file looks like this:

<VirtualHost *:80>
 ServerName www.domain.co.uk

 ProxyPreserveHost On
 RewriteEngine On
 RewriteRule ^/(.*)$ http://server:8000/VirtualHostBase/http/%{HTTP_HOST}:80/root/site/VirtualHostRoot/$1 [L,P]
</VirtualHost>

<VirtualHost *:80>
 ServerName domain.co.uk
 Redirect permanent / http://www.domain.co.uk/
</VirtualHost>

在试图得到这个工作,我追加这一点,只是为了看看,如果我能得到一个子页面重定向:

In an attempt to get this working I appended this, just to see if I could get a sub page to redirect:

<VirtualHost *:80>
 ServerName http://www.domain.co.uk/subpage-a
 Redirect permanent / http://www.domain.co.uk/
</VirtualHost>

这没有工作,但因为有很多子页面到这个网站的,我真的想了解更多这将某些子页面被忽视一个包罗万象的规则。

This didn't work but as there are a lot of sub pages to this site, I really would like more of a catch-all rule which would be ignored for certain sub pages.

这是可能的,并没有任何人有什么想法?

Is this possible and does anyone have any ideas?

感谢。

我在寻找一个包罗万象的风格阿帕奇重写规则,将每个子页面重定向,禁止某些网页域名的主页。

I'm looking for a 'catch-all' style Apache rewrite rule which will redirect every subpage, bar certain pages to the home page of the domain.

至于答案下面我曾尝试以下内容:

With regards to the answers below I have tried the following:

我修改了code到如下所示:

I modified my code to look like the following:

<VirtualHost *:80>
 ServerName sub.domain.co.uk

 ProxyPreserveHost On
 RewriteEngine On
 RewriteCond %{REQUEST_URI} !^/(terms|request-information)(/.*|)$ [NC] 
 RewriteRule ^/(.*)$ http://server:8000/VirtualHostBase/http/%{HTTP_HOST}:80/root/site/VirtualHostRoot/$1 [L,P]
</VirtualHost>

<VirtualHost *:80>
 ServerName domain.co.uk
 Redirect permanent / http://www.domain.co.uk/
</VirtualHost>

但它似乎404包含一个破折号的页面,我可以用这个活不过遗憾的是它要求我列出所有的页面,我想代替项重定向|请求信息上方。

我必须preserve原重写规则,多次重写规则似乎给我这个网站是没有正确重定向的消息在浏览器中,我做了复制和粘贴在此$ C $ç修改细节,必要的,但它导致witg错误。

I must preserve the original re-write rule, multiple re-write rules seem to give me a "This website is not redirecting correctly" message in my browser, I did a copy-and-paste on this code amending the details as necessary but it resulted witg the error.

推荐答案

www.domain.co.uk 虚拟主机部分code>插入此code略低于 RewriteEngine叙述在行:

RewriteCond %{REQUEST_URI} !^/(terms|request-information)(/.*|)$ [NC]
RewriteRule ^ / [L,R=301]

编辑:
多重写规则似乎会导致一个重定向错误,只能使用一个。

Multiple rewrite rules seem to cause a redirection error, only use one.

这篇关于Apache的重定向所有子页面的主页,除了特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆