【问题标题】:Mod_rewrite for url with?用于 url 的 Mod_rewrite?
【发布时间】:2013-11-22 07:50:07
【问题描述】:

我在 StackOverflow 中找不到其他问题的答案。 mod_rewrites 生成器失败了,所以我不知道该怎么做..

我有那个网址:http://example.com/?index&category=football

足球是php的动态生成器,所以分类很多。 所以我想要这样的网址:http://example.com/football

如何用 mod_rewrite 做到这一点? 非常感谢!

【问题讨论】:

  • 你能发布你的 mod_rewrite 代码(.htaccess 文件)

标签: php apache .htaccess mod-rewrite


【解决方案1】:
RewriteEngine on
    RewriteRule ^/([a-zA-Z0-9]+)$ /index.php?category=$1
    #RewriteRule ^/([a-zA-Z0-9]+)/$ /index.php?category=$1

【讨论】:

    【解决方案2】:

    试试:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \ /+\?index&category=([^&\ ]+)
    RewriteRule ^ /%1? [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)$ /?index&category=$1 [L,QSA]
    

    【讨论】:

      【解决方案3】:

      这应该使 URL http://example.com/football 像使用 http://example.com/?index&category=football 一样工作:

      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} -s [OR]
      RewriteCond %{REQUEST_FILENAME} -l [OR]
      RewriteCond %{REQUEST_FILENAME} -d
      RewriteRule ^.*$ - [NC,L]
      RewriteRule ^/?([^/$]*) /?index&category=$1 [L]
      

      第 2 行到第 5 行(从 RewriteCond %{REQUEST_FILENAME} -sRewriteRule ^.*$ - [NC,L])是可选的:它们可以直接提供任何以类别名称命名的现有文件(例如 football)(不使用 /?index&category=...)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-16
        • 2012-02-25
        • 1970-01-01
        • 1970-01-01
        • 2014-03-08
        • 2010-12-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多