简体   繁体   English

将除一页外的所有页面重定向到子域 htaccess

[英]Redirect all pages except one page to sub-domain htaccess

I have a index.php in my main domain root我的主域根目录中有一个 index.php

domain.com/index.php domain.com/index.php

And ive moved my forums which was in the same "root" to a subdomain我将位于同一“根”中的论坛移至子域

forums.domain.com forums.domain.com

I need to Redirect everything except the index.php我需要重定向除 index.php 之外的所有内容

ive tryed loads of ways and none seem to work我尝试了很多方法,但似乎都没有奏效

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !index\.php$
RewriteRule ^(.*)$ http://forums.domain.com [L,R]

RewriteEngine On
RewriteCond %{HTTP_HOST} animelon\.com [NC]
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteRule ^(.*)$ http://forums.domain.com/$1 [R=301,L]

If anyone has any ideas that would be great as for the above codes I would them googling about.如果有人对上述代码有任何想法,我会让他们谷歌搜索。 Cheers干杯

You may use RedirectMatch instead of rewriting, that is, replace all the rewrite block you are showing with:您可以使用 RedirectMatch 而不是重写,也就是说,将您显示的所有重写块替换为:

RedirectMatch ^(/(?!index\.php).*) http://forums.domain.com$1

You can see the full explanation of the regex on Regexr here .您可以在此处查看 Regexr 上正则表达式的完整说明。 In brief, it sends all the URIs NOT beginning with /index.php to forums.domain.com.简而言之,它将所有/index.php开头的 URI 发送到 forums.domain.com。

If you don't need any other rewrite rule, you can turn off rewriting by removing all the lines beginning with "Rewrite" from your .htaccess.如果您不需要任何其他重写规则,您可以通过从 .htaccess 中删除所有以“Rewrite”开头的行来关闭重写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM