Redirect all pages except one page to sub-domain htaccess

大城市里の小女人 提交于 2019-12-08 14:53:58

问题


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.



来源:https://stackoverflow.com/questions/6326062/redirect-all-pages-except-one-page-to-sub-domain-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!