【问题标题】:Converting web.config Url rewrite to .htaccess将 web.config Url 重写转换为 .htaccess
【发布时间】:2013-01-24 09:43:27
【问题描述】:

我已经从运行 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>

所以它的作用是重写 PHP 使用的 ?p= 来显示适当的页面。 那么,这究竟是如何做到的呢?我对 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 rewrite时就是这样。

有什么帮助吗?

【问题讨论】:

    标签: .htaccess iis web-config apache2


    【解决方案1】:

    我已成功将其转换为有效的 .htaccess mod_rewrite 代码。 它似乎比它更容易。我不得不在 Google 中进行更深入的搜索,并找到了一个可行的教程。

    这是我现在使用的代码。

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

    这样就解决了。 ;)

    【讨论】:

      猜你喜欢
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多