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?

Link to comment
Share on other sites

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
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.