【问题标题】:htaccess mod_rewrite part of url to GET variablehtaccess mod_rewrite 部分 url 到 GET 变量
【发布时间】:2012-02-10 22:56:01
【问题描述】:

我有一些这样的网址:

  • http://plutov.by/post/cubique_zf_jquery
  • http://plutov.by/post/mysql_useful_queries

如何在 Apache mod_rewrite 的帮助下打开下一页?

  • http://plutov.by/post/main?title=cubique_zf_jquery
  • http://plutov.by/post/main?title=mysql_useful_queries

另外,这个新的重写规则是否适用于“一个入口点重写”?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

谢谢。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    要使新的重写规则与“一个入口点重写”一起使用,请让您的rewriteRules 像这样:

    QSA 标志是强制,因为您要添加新的查询字符串。

    RewriteEngine On
    
    RewriteRule ^(post)/([\w\d\-]+)/?$ $1/main?title=$2 [QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule . index.php [L]
    

    【讨论】:

    • 如果您不关心现有的查询字符串,QSA 标志不是强制性的。
    【解决方案2】:

    您可以在 .htaccess 中使用类似的内容:

    RewriteRule ^post/(.*)$ post/main?title=$1 [L]
    

    您应该在一个入口点重写规则之前保留此规则。如果规则将触发,则重写规则查找将完成(因为指定了 [L] 选项)

    如果您想在 VirtualHost 上下文中使用这些规则,可能需要对路径进行一些修改

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 2016-01-22
      相关资源
      最近更新 更多