My Permalink custom url is /%post_id%/%postname%/

and my website is in Persian language, for some posts the Permalink is change in URL from

http://www.ahangbaz.com/1300/%d8%a7%d8%a8%db%8c-%d8%b7%d9%be%d8%b4-%da%86%d8%b4%d9%85%d9%87/ into --> http://www.ahangbaz.com/1300/?-???-????/

but this doesn't happen for all post, for e.g following post works fine: ahangbaz.com/1106/%D9%82%DB%8C%D8%B5%D8%B1-%D8%A8%D8%B9%D8%AF-%DA%86%D9%86%D8%AF-%D8%B3%D8%A7%D9%84/

I checked in wp_posts table of wordpress and Post_name seems similar for both posts.

If I change the post_name to English it works fine but when post_name is in Persian,problem occures. web server is IIS 7.5 on windows 2008 R2.


Further tests:

  • I changed the thema and disabled all plugin, it still happens. I checked DB colation and its UTF8.

  • To reproduce the issue use the post_title = ابی - طپش - چشمه and post_name will be %d8%a7%d8%a8%db%8c-%d8%b7%d9%be%d8%b4-%da%86%d8%b4%d9%85%d9%87

  • The same problem happens with categories when the slug is in Persian ahangbaz.com/category/%d8%a7%d8%a8%db%8c doesn't work but when its in English or a number it works ahangbaz.com/category/22.

  • Hm, I get /368/ابی-ستاره-دنباله-دار-ستاره-دنباله-دار/ as URL for this in my installation (Apache server). Maybe a server issue. – fuxia Apr 7 '13 at 8:18
  • Do you have IIS 7.5 environment to reproduce ? it works for some posts like ahangbaz.com/1106/… – Robert Apr 7 '13 at 8:24
  • Unfortunately, I have no IIS 7.5 at hand. Maybe someone else can make further tests. I moved your further information from the comments to the question body to make it easier to read. – fuxia Apr 7 '13 at 8:31
  • in fiddler i can see that GET ahangbaz.com/1300/… HTTP/1.1 ----->>>> HTTP/1.1 301 Moved Permanently Content-Type: text/html; charset=UTF-8 Location: ahangbaz.com/1300/?-???-???? Server: Microsoft-IIS/7.5 – Robert Apr 7 '13 at 8:49
  • 1
    I don't think this is a DB problem. Looks more like URL handling in either the server or PHP. – fuxia Apr 7 '13 at 10:13

The problem as @Indolering mentioned is related to URL Rewrite module that the URLs containing UTF-8 characters is not correctly passed when processed by the URL Rewrite module.

Because I'm not the server owner and I'm unable to install the mentioned hotfix (even though I'm using IIS8.5 the problem is still existed) I had to get around this in somehow.

The solution suggested by @pouria-p for Joomla is also applicable to Wordpress.

Step 1. Update the rewrite rule in the web.config file

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
            <rule name="WordPress" patternSyntax="Wildcard">
                <match url="*"/>
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                    </conditions>

                    <!-- The changes are applied to this line only -->
                    <action type="Rewrite" url="index.php" />
            </rule></rules>
    </rewrite>
  </system.webServer>
</configuration>

The rule will be as following :

<action type="Rewrite" url="index.php?requesturi={URL}" />

Step 2. Update the $_SERVER['REQUEST_URI'] manually by adding the following line to the top of the index.php file :

if(isset($_GET['requesturi']))
  $_SERVER['REQUEST_URI'] = $_GET['requesturi'];
  • This workaround is also applicable for using free version of Polylang plugin. The plugin uses posts and pages' name in URL and IIS share hosting routes it like site.com/mm/????? . – M. Ko Oct 17 at 7:40
  • You solution is partly correct. If we put those 2 lines in index.php file by updating of WordPress it will be gone. So I suggest to put if(isset($_GET['requesturi'])) $_SERVER['REQUEST_URI'] = $_GET['requesturi']; inside the functions.php of your child theme. It means you have to create a child theme if you don't have and put these 2 lines at the beginning of that file. – Mahdi J.Ansari Nov 7 at 19:11

I don't have comment capabilities, but the problem is very likely to be on the MS server side, specifically the URL Rewrite module. This is what handles permalinks on IIS. There is a hotfix for this problem, but you should probably apply all the hotfixes available for your system.

  • Well, IMO, this is much more an Answer than a Comment. But adding a summary from the external link would improve greatly the quality of the answer. – brasofilo May 13 '13 at 4:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.