Redirect all pages except one page to sub-domain h

2019-06-09 04:35发布

问题:

I have a index.php in my main domain root

domain.com/index.php

And ive moved my forums which was in the same "root" to a subdomain

forums.domain.com

I need to Redirect everything except the 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

回答1:

You may use RedirectMatch instead of rewriting, that is, replace all the rewrite block you are showing with:

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

You can see the full explanation of the regex on Regexr here. In brief, it sends all the URIs NOT beginning with /index.php to 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.