/    Sign up×
Community /Pin to ProfileBookmark

I need help with some mod_rewrite rules

This is not exactly PHP but as it is so much related to Apache I considered this place the most suitable to post this question.

I want to create pagination with .htaccess so that this would be the appearance of the URL:

page 1 would be this way:
[url]http://www.mydomain.com/game/name-of-game-sef/review/[/url]

from page 2 on the URL would change a little:
[url]http://www.mydomain.com/game/name-of-game-sef/review/[/url][B]2/[/B]
[url]http://www.mydomain.com/game/name-of-game-sef/review/[/url][B]3/[/B]

[url]http://www.mydomain.com/game/name-of-game-sef/review/[/url][B]n/[/B]

It might also be like this, if the review was specially made for an only platform (PS3, Xbox, etc):
[url]http://www.mydomain.com/game/sef-name-of-game/[/url][B]ps3[/B]/review/3/

These are the rules I created in order to manage these URL’s from Apache and redirect the request to the proper php file:

[CODE]# for pages from 2 on
RewriteRule ^game/([_0-9a-z-]+)/?([_0-9a-z-]+)?/review/([0-9]+)/ reviews.php?idgame=$1&idplatform=$2&page=$3 [L]
# for page 1
RewriteRule ^game/([_0-9a-z-]+)/?([_0-9a-z-]+)?/review/ reviews.php?idgame=$1&idplatform=$2&page=1 [L][/CODE]

I’m not keen on regular expressions :rolleyes:, and only the first page can be displayed. When I click on page 2, 3, etc, it always displays the first one.

I’ve also tried testing it on a local machine with XAMPP, but in this case no matter what I do, even if I delete .htaccess, it returns a 301 error (Moved permanently) and I can’t access index.php

Could somebody please shed a light on this?? ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@gvreMay 18.2011 — A more flexible solution would be the following. Then, you can parse the uri with php ( $_SERVER['REQUEST_URI'] ).

[CODE]RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php[/CODE]
Copy linkTweet thisAlerts:
@JazztronikauthorMay 18.2011 — Thanks for your reply!

Could you please explain what RewriteCond and its parameters would do? I never used it.
Copy linkTweet thisAlerts:
@gvreMay 19.2011 — From apache's manual.

REQUEST_FILENAME

The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual host context, the same value as REQUEST_URI.

'-d' (is directory)

Treats the TestString as a pathname and tests whether or not it exists, and is a directory.

'-f' (is regular file)

Treats the TestString as a pathname and tests whether or not it exists, and is a regular file.

You can prefix the pattern string with a '!' character (exclamation mark) to specify a non-matching pattern.
×

Success!

Help @Jazztronik spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...