2

This relates to my previous question (which can be viewed here). I'd like to be able to remove the trailing slash from the URL so that it doesn't mess up certain areas of my site. The .htaccess code is here:

# -s = File Exists RewriteCond %{REQUEST_FILENAME} -s [OR] # -l = Is a SymLink RewriteCond %{REQUEST_FILENAME} -l [OR] # -d = Is a Directory RewriteCond %{REQUEST_FILENAME} -d # if we match any of the above conditions - serve the file. RewriteRule ^.*$ - [NC,L] # only allows '.' in the "page" portion. RewriteRule ^([^/.]+)/?$ index.php?section=$1 [L] RewriteRule ^([^/.]+)/([^/]+)/?$ index.php?section=$1&page=$2 [L] RewriteRule ^([^/.]+)/([^/]+)/([^/.]+)/?$ index.php?section=$1&page=$2&split=$3 [L] 

As before, I'm out of my depth with this, so can anyone help out?

5
  • 1
    Am I right in thinking it's the regex you're having trouble with? Commented Sep 2, 2009 at 15:11
  • I suggested migrating this to serverfault where there are probably a lot more Apache admins. Commented Sep 2, 2009 at 15:12
  • Sorry, not quite sure what you're asking. Doesn't your .htaccess already remove the slashes? Commented Sep 2, 2009 at 15:24
  • The page served will be the same, but if the trailing slash is present then relative URIs will change. I.e a relative link from /page/etc to ./melon will be fine, linking to /page/melon, but /page/etc/ to ./melon will link to /page/etc/melon. Commented Sep 2, 2009 at 15:29
  • I don't think you can change what is shown in the address bar, which in turn means that whatever rewrites are done serverside, a link will always go from /page/etc/ to /page/etc/melon. You've got to rewrite the target server-side, I think. Why is there a dot before the slash: ./melon. Commented Sep 2, 2009 at 15:44

1 Answer 1

5

I assume you are talking about the rule:

RewriteRule ^.*$ - [NC,L] 

As the other already omit the trailing slash.

Try this instead:

RewriteRule ^(.*)/$ $1 [NC,L] 

Here's what I see in the logs (abbreviated):

applying pattern '^(.*)/$' to uri 'host/' rewrite 'host/' -> 'host' 

So that seems OK to me.

Sign up to request clarification or add additional context in comments.

1 Comment

You should better use a permanent redirect than just an internal rewrite.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.