简体   繁体   中英

IIS URL Rewrite mobile folder

Hi I have a site that used to have a separate mobile side which had links indexed by google. I've now changed that to a responsive design. I'm on a shared server so I have to do this redirect through URL Rewrite, is there any way that I can redirect anything and everything that comes after the /mobile/ subfolder that used to exist to its equivalent in a root folder with one rule. So that the following would happen:

Domain.com/mobile -> domain.com
Domain.com/mobile/folder1/page1/variable -> domain.com/folder1/page1/variable
Domain.com/mobile/folder1/page2/variable -> domain.com/folder1/page2/variable
Domain.com/mobile/folder2/page1/variable -> domain.com/folder2/page1/variable
Domain.com/mobile/folder2/page2/variable -> domain.com/folder2/page2/variable

That would look something like the following in your web.config (basicall match all "root" requests that start with mobile/ and redirect to the equivalent (using a 301 which is the right one for SEO purposes):

<configuration>
    <system.webServer>    
        <rewrite>
            <rules>
                <rule name="Redirect mobile" stopProcessing="true">
                    <match url="^mobile/(.*)$" />
                    <action type="Redirect" url="{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM