I would like to redirect users coming from : http://www.example.com/trial/test to http://www.example.com/trial/test/ and from there to http://www.example.com/load_page.php?page=test I tried this RewriteEngine on RewriteRule ^trial/(.*)$ trial/$1/ [R] RewriteRule ^trial/(.*)/(.*)/$ load_page.php?page=$1 and a few alterations of the above but it either appends the physical path to the domain name or appends loads of trailing slashes to the URL. Can anybody help me out with this please?
Set up a rewrite cond that checks if the requested URI ends in a trailing slash. If not, redirect and stop rewriting. If we do get to the next rule, we know it does have a trailing slash so just do the rewrite. RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !/$ RewriteRule ^trial/(.+)$ trial/$1/ [R=301,NC,L] RewriteRule ^trial/(.+)/ load_page.php?page=$1 [NC,L] Code (markup): That redirects everything (files and directories) in the trial folder to have a trailing slash. If you only want that for directories you can add another RewriteCond to check the request for a .ext
Thx 4 your reply rodney88! If R = redirect, what are NC and L? Also will http://www.example.com/newpage.html be checked for a trailing slash with the codes you provided?
Everything in the trial directory will be given a trailing slash. example.com/anypage.html won't because it's not in the /trial/ folder. NC is no case / case-insensitive. The L flag is for "last" so that it doesn't try to apply any more rewrite rules that may follow.
Absolutely brilliant! Thx a lot rodney88. Ohh if i wanted to have a second redirect, would the below code be correct? RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !/$ RewriteRule ^trial/(.+)$ trial/$1/ [R=301,NC,L] RewriteRule ^trial/(.+)/ load_page.php?page=$1 [NC,L] RewriteCond %{REQUEST_URI} !/$ RewriteRule ^testing/(.+)$ testing/$1/ [R=301,NC,L] RewriteRule ^testing/(.+)/ load_page.php?page=$1 [NC,L] Code (markup):