转换web.config Url重写为.htaccess

时间:2013-01-24 09:43:27

标签: .htaccess iis web-config apache2

我已经从运行IIS7.5的Windows Server 2008 R2切换到运行Apache2的CentOS服务器,因为我遇到了PHP的性能问题。

我的主站点的Web.config使用url重写并需要转换。自从我上次使用.htaccess文件以来已经有一段时间了。 我的Web.Config重写代码:

  <rule name="IndexRewrite" stopProcessing="true">
        <match url="^([^/]+)/?$" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="index.php?p={R:1}" />
    </rule>

它的作用是重写?p = PHP使用它来显示适当的页面。 那么,这究竟是怎么做到的呢?我不熟悉Apache2中的mod_rewrite。

我尝试使用SocialEngine修改来自其他网站的重写规则,坚定不运。

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On

  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?p= [L,QSA]
  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*) index.php?p= [L,QSA]


</IfModule>

链接示例: http://example.com?p=about 应该 http://example.com/about

<小时/> 就是在我使用IIS7.5 Url重写之前的情况。

任何帮助?

1 个答案:

答案 0 :(得分:1)

我已成功将其转换为工作的.htaccess mod_rewrite代码。 它似乎比它更容易。我不得不在Google深入搜索并找到了一个有用的工作。

这是我现在使用的代码。

RewriteEngine On
RewriteBase /
RewriteRule ^([A-z]+)$ /index.php?p=$1

所以这个问题已经解决了。 ;)