dustinnoe Posted March 26, 2007 Share Posted March 26, 2007 I have the following rule: RewriteRule ^(latest|latest/)$ index.php It works great when I include the trailing slash in the URL. When the trailing slash is absent all of my relative links drop the 'latest' directory and move up one directory. How do I force recognition of a directory when there is no trailing slash? Link to comment https://forums.phpfreaks.com/topic/44299-solved-relative-links-and-trailing-slashes/ Share on other sites More sharing options...
dustinnoe Posted March 28, 2007 Author Share Posted March 28, 2007 OK! I found a solution, directly from Apache, but that same solution creates another problem. Here are the rewrite rules: RewriteBase / RewriteRule ^latest$ latest/ [R] RewriteRule ^latest/?$ index.php RewriteRule ^latest/page(.*).html$ index.php?page=$1 RewriteRule ^user/(.*)$ user/$1/ [R] RewriteRule ^user/(.*)/$ journal.php?user=$1 RewriteRule ^user/(.*)/page([0-9]+).html$ journal.php?user=$1&page=$2 The top set of rewrite rules works great but on the second set when I introduce a variable it adds two trailing slashes instead of one. So if the user enters http://mydomain.com/user/username (with or without the trailing slash) mod_rewrite outputs this http://mydomain.com/user/username// Any ideas? Link to comment https://forums.phpfreaks.com/topic/44299-solved-relative-links-and-trailing-slashes/#findComment-216509 Share on other sites More sharing options...
dustinnoe Posted March 28, 2007 Author Share Posted March 28, 2007 Allrighty, I solved my own problem again. After taking a nice break from nearly punching the computer screen out of frustration I realized what had happened. The Regex I was feeding the pattern was matching the forward slash character, duh! So I just specified what the pattern should match. New Rules: RewriteBase /qt/ RewriteRule ^latest$ latest/ [R] RewriteRule ^latest/?$ index.php RewriteRule ^latest/page(0-9]+).html$ index.php?page=$1 RewriteRule ^user/([a-zA-Z0-9_]+)$ user/$1/ [R] RewriteRule ^user/([a-zA-Z0-9_]+)/$ journal.php?user=$1 RewriteRule ^user/([a-zA-Z0-9_]+)/page([0-9]+).html$ journal.php?user=$1&page=$2 Ahh, I feel much better now. Link to comment https://forums.phpfreaks.com/topic/44299-solved-relative-links-and-trailing-slashes/#findComment-216557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.