【问题标题】:Understanding RewriteRule & HTACCESS了解 RewriteRule 和 HTACCESS
【发布时间】:2016-01-08 21:13:00
【问题描述】:

我正在构建一个页面结构非常简单的博客,由articles.phparticle.phpcategories.php 组成,我想整理每个页面的 url 路径,但是我遇到了麻烦了解模组的工作原理。

目前我的articles 页面是主页,使用DirectoryIndex 完成,但我的网址看起来像:

http://testblog.local.co.uk/?cat=all&currentpage=3

我希望它在哪里:

http://testblog.local.co.uk/all/3

到目前为止,我的 htaccess 代码如下所示:

DirectoryIndex articles.php
RewriteEngine On
RewriteRule ^/?([a-zA-Z_]+)/([0-9]+)$ articles.php?cat=$1&currentpage=$2 [L]

这对 url 没有任何作用,也不会正确显示页面。我浏览了无数在线“初学者指南”,但仍然无法解决。有人可以帮忙吗?

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting friendly-url


    【解决方案1】:

    使用%{THE_REQUEST} 变量:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ^GET\ /articles\.php\?cat=([^&]+)&currentpage=(\d+) [NC]
    RewriteRule ^ /%1/%2? [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/(\d+)/?$ /articles.php?cat=$1&currentpage=$2 [L]
    

    【讨论】:

      猜你喜欢
      • 2012-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多