【问题标题】:URL Rewrite/Mod Rewrite .htaccess on Apache and PHPApache 和 PHP 上的 URL 重写/Mod 重写 .htaccess
【发布时间】:2012-02-27 22:02:28
【问题描述】:

我的网站上只有一个入口点

mysite.com/admin/index.php?<strong>View=List&amp;Model=User</strong>

对数据库/应用程序的所有访问都是通过这个 index.php 文件。

我想从上面显示的内容中清除我的 URL。

mysite.com/admin/<strong>List/User</strong>

这个想法是删除关键的“模型和视图”。

我发现这个链接看起来非常相似。

PHP/Apache: Rewrite rules with .htaccess

【问题讨论】:

  • 所有选项似乎都不起作用。我有一种感觉我错过了一个模块
  • LoadModule rewrite_module modules/mod_rewrite.so 已启用,是否还有需要启用的模块?

标签: php apache url-rewriting


【解决方案1】:

在 htaccess 文件中插入此代码:

RewriteEngine On
RewriteRule ^admin/([^/]*)/([^/]*)$ /admin/index.php?View=$1&Model=$2 [L]

改写后的网址:

http://mysite.com/admin/List/User

这个站点对于生成重写 URL 非常有用

http://www.generateit.net/mod-rewrite/

【讨论】:

    【解决方案2】:

    如果您还没有以下文件,请在您的 Web 根目录中创建一个名为 .htaccess 的文件:

    # Turn the rewrite engine on (skip this if already done)
    RewriteEngine On
    
    # Redirect admin/List/User/ to admin/index.php?View=List&Model=User
    RewriteRule ^admin/([^/.]+)/([^/.]+)/?$ admin/index.php?View=$1&Model=$2 [L]
    

    【讨论】:

      【解决方案3】:

      这可能有效:

      Options +FollowSymlinks
      RewriteEngine on
      RewriteRule ^admin/([^/]+)/([^/]+) /index.php?View=$1&Model=$2 [NC]
      

      添加到您网站根文件夹中的 .htaccess。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-03
        相关资源
        最近更新 更多