Need Help With My Web.config File (Canonical Issue)

Davidnrog

Regular Member
Joined
Apr 21, 2014
Messages
218
Reaction score
32
I'm working on my new website which is facing some canonical error.
I've moved my website to http://www.example.com from (without)example.com by using the code below

(Note :fixed the www and no-www error)

I want my website redirect's, when i type "www.example.com/index.php" to "www.example.com"

"(i.e. I don?t want to have the ?index.php? portion visible in the address)"

Code:
<configuration> 
  <system.webServer> 
    <rewrite> 
      <rules> 
        <rule name="Redirect to WWW" stopProcessing="true"> 
          <match url=".*" /> 
          <conditions> 
            <add input="{HTTP_HOST}" pattern="^example.com$" /> 
          </conditions> 
          <action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" /> 
        </rule> 
      </rules> 
    </rewrite> 
  </system.webServer> 
</configuration>



Thank's

Please Help..
 
I'm still waiting to get some expert suggestion for this issue.
 
Strange, why are you trying to remove index.php with a web.config file? Is your site in ASP.NET or is it in PHP?
 
The website is in Php, I've implement the above code in my web.config When i visit to my site "http://www.example.com" or "http://www.example.com/index.php" With and Without index.php; it is presented with the exact same page, and having the same content and it resolve's at two different website url. I know it's potentially harmful for search engine ranking...
 
and you can easily get a proper solution of your problem in other webmaster forums like stack overflow etc.
 
If your website is in PHP, then why is there a web.config file? Web.config contains
settings for ASP.NET web apps. If your site's in PHP use a .htaccess file to remove
the index.php from the URL.

EDIT: I pasted the .htaccess that I use:

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
 
Last edited:
As per my knowledge .haaccess is for those website which are on Apache server. My website is on the flexible (IIS) 8 Windows Server.
 
Last edited:
As per my knowledge .haaccess is for those website which are on Apache server. My website is on the flexible (IIS) 8 Windows Server.

That's right. So it's a PHP site on an IIS server, that's a bit unusual but whatever.

Here you go:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument enabled="true">
            <files>
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="cleanurls" enabled="true" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
 
Back
Top