简体   繁体   中英

web.config & Aruba - URL Rewrite

I'm developing my first website and just learnt about the web.config file for IIS, so what I'm trying to do is to hide different parts of the url.

For example the homepage is www.domain.com/it/homepage.html and I'd love to make it appear as www.domain.com/it/homepage I haven't found anything about removing an .html extension on the net, just a lot of .aspx which I tryed to replace with .html, failing miserably.

Another side question: is it possible to redirect errors with web.config ? I've seen a lot of .htaccess based solutions but that's it.

EDIT: Forgot to say that the website is hosted by ARUBA, on their windows oriented server

You are trying to change the URL of your site, which is the way to access it... that's a pretty odd action to do. When you get a request to your server for a certain page, the URL is parsed as the path to that file. If you want to change the URL, you need to change the name of the file - and if you wouldn't like having a .html in the end, then perhaps the file shouldn't be a html file - however, your goal is different. You want to have no extension at all.

Luckily, there is a way to have a url endpoint which doesn't have any file extension is all. That would be a folder. Folders dont have an extension to them, however they have no content by themselvs except the file they're linking.

Side note: There's another way, which is the one you'd usually see around the web. PHP could have other things in the URL than just the endpoint, but you asked about windows based HTML/ASPX windows backed pages.

So - yeah, the only way I see to have no extension at all is letting the user navigate through folders. The only question left is, why would you want this anyway?

You can use the following configuration in your web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="niceURL"  stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="{R:0}.html" appendQueryString="true" />
                </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