2014-08-27 41 views
0

我想指向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

回答

0

我已經通過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> 
0

您需要在重寫規則之前保持重定向。試試這個代碼:

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