<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Add slashes to the end of everything, if not present:
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://localhost/$1/ [R=301,L]
# Redirect about/ and about/X to about.php?get=X:
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^about/$ about.php
RewriteRule ^about/([A-Za-z\+\-]+)/?$ about.php?get=$1
</IfModule>
This rule basically added a trailing slash to a URL and mapped URLs to www.example.com/page/ rather than page.php
I've set myself a little goal, to take a pagination script and use .htaccess to clean it up. so where a url was previously:
www.example.com/page.php?s=30&p=4 /* In my example I'm only using a set of 11 results and display 2 results per page just so I had a decent number of pages to test but didnt have to write loads of Data */
it would look like
www.example.com/page/4
So I started quite basic with the .htaccess and thought i'd build it up, so my initial code mapped "test" to "test.php" was: (Here i'm not adding trailing slashes to everything by the way)
<IfModule mod_rewrite.c> RewriteEngine on #RewriteRule ^test$ test.php #RewriteRule ^test/([0-9\+\-]+)$ test.php?s=$1&p=$2 </IfModule>
But I've started to confuse myself now really. If I type:
http://localhost/test -> returns Result 1 + Result 2 :-)
http://localhost/test/1 -> returns Result 2 + Result 3 :-)
http://localhost/test/2 -> returns Result 3 + Result 4 :-) /* You can see where this is going */
Obviously this is wrong, It would suggest to me that my $_GET['s'] is being mapped as the row to start at from what ever number follows the final slash i.e. /2
Which got me thinking how to correct this and also not mess up my links either. So does anyone have any pointers?











