重写规则重定向url在不同的域

问题描述:

我想指向subdomain.domain.net到www.subdfgomain.com或whaterver,我尝试使用htaccess规则,但没有得到结果,请帮助!重写规则重定向url在不同的域

# BEGIN WordPress 
<IfModule mod_rewrite.c> 

RewriteEngine On 

RewriteBase /project/projectname/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /project/projectname/index.php [L] 

RewriteCond %{HTTP_HOST} ^projectname.domain.net 
RewriteRule (.*)$ http://www.another.com/$1 [R=301,L] 

</IfModule> 

# END WordPress 
+0

为什么你不在你的代码中显示WP规则,你得到了什么错误? – anubhava 2014-08-27 11:08:06

+0

我没有收到任何错误,但是这个重写规则在站点中没有出现任何内容 – gayatri 2014-08-27 11:45:12

+0

这是唯一的规则还是您还有其他规则? – anubhava 2014-08-27 11:49:19

我已经通过web.config管理,现在它的工作。

<?xml version="1.0" encoding="UTF-8"?> 
    <configuration> 
     <system.webServer> 
      <rewrite> 
       <rules> 
        <rule name="WordPress Rule 1" stopProcessing="true"> 
         <match url="^index\.php$" ignoreCase="false" /> 
         <action type="None" /> 
        </rule> 
        <rule name="WordPress Rule 2" stopProcessing="true"> 
         <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" /> 
         <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" /> 
        </rule> 
        <rule name="WordPress Rule 3" stopProcessing="true"> 
         <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" /> 
         <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" /> 
        </rule> 
        <rule name="WordPress Rule 4" stopProcessing="true"> 
         <match url="^" ignoreCase="false" /> 
         <conditions logicalGrouping="MatchAny"> 
          <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> 
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> 
         </conditions> 
         <action type="None" /> 
        </rule> 
        <rule name="WordPress Rule 5" stopProcessing="true"> 
         <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" /> 
         <action type="Rewrite" url="{R:2}" /> 
        </rule> 
        <rule name="WordPress Rule 6" stopProcessing="true"> 
         <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" /> 
         <action type="Rewrite" url="{R:2}" /> 
        </rule> 
        <rule name="WordPress Rule 7" stopProcessing="true"> 
         <match url="." ignoreCase="false" /> 
         <action type="Rewrite" url="index.php" /> 
        </rule> 
       </rules> 
      </rewrite> 
     </system.webServer> 
    </configuration> 

您需要在重写规则之前保持重定向。试试这个代码:

RewriteEngine On 
RewriteBase /project/projectname/ 

RewriteCond %{HTTP_HOST} ^projectname\.domain\.net$ [NC] 
RewriteRule^http://www.another.com%{REQUEST_URI} [R=301,L,NE] 

RewriteRule ^index\.php$ - [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /project/projectname/index.php [L] 
+0

'[NC] L NE'是什么意思?你可以分享任何资源来了解更多信息吗? – 2014-08-27 12:00:42

+0

确定您检查http://httpd.apache.org/docs/current/rewrite/intro.html,然后http://askapache.com – anubhava 2014-08-27 12:02:02

+1

'NC - 忽略案例比较,NE - 无编码,L - 最后一条规则当前循环'。 – anubhava 2014-08-27 12:02:56