Forum Moderators: phranque

Message Too Old, No Replies

Adding a trailing slash in htaccess rewrite

Adding a slash without exposing the directory

         

calvinmicklefinger

3:55 pm on Jun 1, 2005 (gmt 0)

10+ Year Member



I have the following .htaccess file ...

# .....................
DirectoryIndex ./php/content.php

# Start your engines
RewriteEngine on

# Set up the paths to follow
Options +FollowSymlinks -Indexes
RewriteBase /

# Enable access to Site Manager
ReWriteRule ^manager$ manager [L]

# Restrict Access to site resources images, etc.
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite\.com/.*$ [NC]
RewriteRule \.(gif¦jpe?g¦png¦bmp)$ - [F,NC,L]
RewriteRule ^\.htaccess$ - [F]

# Allow Perl Scripts to run
RewriteRule ^cgi-bin/y/d.cgi/?([a-z]+)-IPP([0-9]+)$ - [NC,L]

# Allow Properly formatted URL to access content
RewriteRule ^([a-z0-9]{5})/([a-z0-9]+)/?$ ./php/content.php [NC,L]

# Allow URL without pagename to access main page and assign default AFF_NUM
ReWriteRule ^([a-z0-9]+)/?$ [mysite.com...] [NC,R=301,L]

# ....................

How would I add a trailing slash to the displayed URL without changing the operation of the rules?

Many thanks for any assistance.

mexicoshanty

4:03 pm on Jun 1, 2005 (gmt 0)

10+ Year Member



hey calvinmicklefinger

I'm only new to this suff but i think this is what you're after, had a similar problem and jdMorgan helped me out with this code.

# If path does not end in "/"
RewriteCond %{REQUEST_URI}!/$
# and does not contain a "."
RewriteCond %{REQUEST_URI}!\.
# then add trailing slash and redirect
RewriteRule ^(.*) /$1/ [R=301,L]

This will redirect a page like domain.com/page to domain.com/page/

Hope this helps,
Coen

mexicoshanty

4:05 pm on Jun 1, 2005 (gmt 0)

10+ Year Member



You'll probably have to customize it to suit your needs but it give the general idea

calvinmicklefinger

4:37 pm on Jun 1, 2005 (gmt 0)

10+ Year Member



Thanks Coen,

It does give a start, but unfortunately it conflicts with php in my pages.

I'm looking at maybe seeing if it's possible to pre-pend a slash to a querystring. Any ideas you've seen?

CM