Jump to content

[SOLVED] Relative links and trailing slashes


dustinnoe

Recommended Posts

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?

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?

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! :D  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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.