Apache htaccess有一些问题!

Apache htaccess有一些问题!,apache,.htaccess,http-status-code-301,Apache,.htaccess,Http Status Code 301,如何将用户从example.com/或www.example.com重定向到new.example.com 但我不想重定向某些特定URL,如: www.example.com/test.php api.example.com/testo.php www.example.com/forum/index.php 我做到了: 但是URL的规则是什么?一种方法是在.htaccess文件的前面为特定URL创建额外的规则,这些URL只是在内部重定向到自身,而不是使用3XX响应,然后使用L标志,这样以后就不

如何将用户从example.com/或www.example.com重定向到new.example.com

但我不想重定向某些特定URL,如:

www.example.com/test.php
api.example.com/testo.php
www.example.com/forum/index.php
我做到了:


但是URL的规则是什么?

一种方法是在.htaccess文件的前面为特定URL创建额外的规则,这些URL只是在内部重定向到自身,而不是使用3XX响应,然后使用L标志,这样以后就不会为这些URL处理任何规则

例如:

RewriteEngine on

# don't redirect these
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(/test.php)$ \1 [L]

RewriteCond %{HTTP_HOST} ^api.example.com$
RewriteRule ^(/testo.php)$ \1 [L]

RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(/forum/index.php)$ \1 [L]

# redirect these
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://new.example.com/$1 [R=301,L]
我不确定您的不重定向要求是否包括主机名。如果没有,则只需删除重写条件行

RewriteEngine on

# don't redirect these
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(/test.php)$ \1 [L]

RewriteCond %{HTTP_HOST} ^api.example.com$
RewriteRule ^(/testo.php)$ \1 [L]

RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(/forum/index.php)$ \1 [L]

# redirect these
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://new.example.com/$1 [R=301,L]