重写不同域上重定向网址的规则

时间:2014-08-27 11:04:43

标签: wordpress .htaccess

我想将subdomain.domain.net指向www.subdfgomain.com或whaterver,我尝试使用htaccess规则但没有得到结果,请帮助!!

    # 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

2 个答案:

答案 0 :(得分: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]

答案 1 :(得分: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>