renata costa
renata costa

Reputation: 177

Friendly url pagination

I am new on that htaccess thing.

My problem is, I have a pagination on index.php:

http://localhost/index.php?pagina=2

I want to access this with this url:

http://localhost/page/2

I try on htaccess:

RewriteEngine On
RewriteRule /page/(.*)$ index.php?pagina=$1 

but it gave me a 404 error.

Upvotes: 1

Views: 578

Answers (2)

MrWhite
MrWhite

Reputation: 45829

In per-directory .htaccess files the directory prefix, of where this .htaccess file is located, is removed from the URL-path when pattern matching. In the document root, this is simply / (a slash). So your RewriteRule would need to be rewritten as:

RewriteRule ^page/(.*) /index.php?pagina=$1 [L]

Upvotes: 1

Croises
Croises

Reputation: 18671

Use:

RewriteEngine On
RewriteRule page/(.*)$ index.php?pagina=$1

without first /

Upvotes: 0

Related Questions