[英]Redirect all pages except one page to sub-domain htaccess
我的主域根目录中有一个 index.php
domain.com/index.php
我将位于同一“根”中的论坛移至子域
forums.domain.com
我需要重定向除 index.php 之外的所有内容
我尝试了很多方法,但似乎都没有奏效
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]
如果有人对上述代码有任何想法,我会让他们谷歌搜索。 干杯
您可以使用 RedirectMatch 而不是重写,也就是说,将您显示的所有重写块替换为:
RedirectMatch ^(/(?!index\.php).*) http://forums.domain.com$1
您可以在此处查看 Regexr 上正则表达式的完整说明。 简而言之,它将所有不以/index.php
开头的 URI 发送到 forums.domain.com。
如果您不需要任何其他重写规则,您可以通过从 .htaccess 中删除所有以“Rewrite”开头的行来关闭重写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.