RewriteEngine Rules

Posted on 2011-10-03
Last Modified: 2012-06-27
I am trying to make some rewrite rules, but I am having issues with some of them. Can anyone help me out here?

These rules work:
RewriteRule ^blog$ blog.php [L]
RewriteRule ^blog/page/(.*)$ blog.php?page=$1 [L]
RewriteRule ^blog/category/(.*)/(.*)$ blog.php?cat=$1 [L]

But when I need to paginate that last rule, like this:
RewriteRule ^blog/category/(.*)/(.*)/page/(.*)$ blog.php?cat=$1&page=$3 [L]

It just doesn't. I guess it's because of the first rule having the (.*)...

Question by:ApOG
    LVL 14

    Expert Comment

    >RewriteRule ^blog$ blog.php [L]
    >RewriteRule ^blog/page/(.*)$ blog.php?page=$1 [L]
    >RewriteRule ^blog/category/(.*)/(.*)$ blog.php?cat=$1 [L]
    for rule 3 try this (assuming there are no slashes required in $2)
    RewriteRule ^blog/category/(.*)/([^/]*)$ blog.php?cat=$1 [L]

    Author Comment

    Thanks DonConsolio..

    I tried it, but with no luck.

    This: is exactly like using:


    Accepted Solution

    Well I figured it out.

    The 4th rule must be before the third rule. And that's it! :)

    Author Closing Comment

    This solved my issue.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
    If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now