I’m having a hard time perfecting the rewrite rules for a subdirectory with pagination.
I have a directory named /files which resides in the root of my website. ex: www.site.com/files
The index.php script located in /files displays a list of all possible files if the URL is simply www.site.com/files
This is achieved with the following .htaccess script:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-z0-9]+)$ index.php?fileid=$1 [NC]
</IfModule>
The /files directory includes a diretory named /users
The /users/index.php script will display a list of files specific to a user if a user ID is included in the URL, e.g. www.site.com/files/user/101
This is working with an .htaccess file which looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-z0-9]+)$ index.php?userid=$1 [NC]
</IfModule>
I would like to add pagination to the list of files provided by both of these index.php scripts.
For example if I am showing 25 results per page:
www.site.com/files/1 would show the first page of all files, one through twenty-five.
www.site.com/files/2 would show the second page of all files, twenty-six through fifty.
And then the user-specific listings would be:
www.site.com/files/user/101/1 would show the first page of all files belonging to user 101, one through twenty-five.
www.site.com/files/user/101/2 would show the second page of all files belonging to user 101, twenty-six through fifty.
Bonus:
http://www.site.com/files/1 and http://www.site.com/files/1/ should return the same page.
http://www.site.com/files/user/101/1 and http://www.site.com/files/user/101/1/ should return the same page.
Should I be handling this with a single .htaccess file instead of one in the /files directory and one in the /user directory?
Can someone help me modify the rewrite rules to handle pagination?
RewriteRule ^([a-z0-9]+)/?$ index.php?pages=$1 [NC]
You can test it here